diff --git a/__tests__/api/BundleContent/AutoBundler.test.ts b/__tests__/api/BundleContent/AutoBundler.test.ts index b4dd70d1..8e86d6f8 100644 --- a/__tests__/api/BundleContent/AutoBundler.test.ts +++ b/__tests__/api/BundleContent/AutoBundler.test.ts @@ -13,6 +13,7 @@ import { AutoBundler } from "../../../src/api/BundleContent/AutoBundler"; import { IHandlerParameters } from "@zowe/imperative"; import * as GenerateBundleDefinition from "../../../src/cli/generate/bundle/GenerateBundle.definition"; import * as fse from "fs-extra"; +import { Readable } from "stream"; const DEFAULT_PARAMETERS: IHandlerParameters = { @@ -21,11 +22,6 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "generate", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - return {}; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { @@ -42,16 +38,17 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { error: jest.fn((errors) => { expect("" + errors).toMatch("NO ERRORS ARE EXPECTED"); }), - errorHeader: jest.fn(() => undefined) + errorHeader: jest.fn(() => { fail("No errors are expected") }) }, progress: { - startBar: jest.fn((parms) => undefined), - endBar: jest.fn(() => undefined) + startBar: jest.fn((parms) => fail("Unexpected") ), + endBar: jest.fn(() => fail("Unexpected") ) } } as any, definition: GenerateBundleDefinition.GenerateBundleDefinition, fullDefinition: GenerateBundleDefinition.GenerateBundleDefinition, positionals: [], + stdin: new Readable() }; describe("AutoBundler01", () => { @@ -124,6 +121,7 @@ describe("AutoBundler01", () => { let err: Error; try { const ab = new AutoBundler("__tests__/__resources__/ExampleBundle01", parms); + fail("Should have thrown error condition"); } catch (e) { err = e; } @@ -195,6 +193,7 @@ async function runAutoBundleWithError(parms: IHandlerParameters, dir: string) { let err: Error; try { const ab = new AutoBundler(dir, parms); + fail("Should have thrown error condition"); } catch (e) { err = e; } diff --git a/__tests__/api/BundleContent/BundleMocked.test.ts b/__tests__/api/BundleContent/BundleMocked.test.ts index 8b693fb6..dabffde6 100644 --- a/__tests__/api/BundleContent/BundleMocked.test.ts +++ b/__tests__/api/BundleContent/BundleMocked.test.ts @@ -22,11 +22,11 @@ describe("MockedFilesystemTests", () => { it("should tolerate META-INF directory not existing", () => { // Mocks for the manifest - META-INF exists - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("META-INF")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("META-INF")) { return false; } - if (path.endsWith(".zosattributes")) { + if (path.toString().endsWith(".zosattributes")) { return false; } return true; @@ -35,17 +35,14 @@ describe("MockedFilesystemTests", () => { // Mocks for the manifest - Bundle dir writable jest.spyOn(fs, "accessSync").mockImplementationOnce(() => ( true )); - let err: Error; try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, false); bund.prepareForSave(); } catch (error) { - err = error; + fail(error); } - - expect(err).toBeUndefined(); - }); + } ); it("should complain if no write permission to bundle directory", () => { // Mocks for the manifest - META-INF doesn't exist jest.spyOn(fs, "existsSync").mockImplementationOnce(() => ( false )); @@ -56,6 +53,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, false); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -75,6 +73,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, false); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -94,6 +93,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, false); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -107,8 +107,8 @@ describe("MockedFilesystemTests", () => { // Mocks for the manifest - META-INF & manifest exist jest.spyOn(fs, "existsSync").mockReturnValue(true); // Mocks for the manifest - META-INF is writable, but manifest is not. - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { throw new Error("Wibble"); } return true; @@ -118,6 +118,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, true); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -129,58 +130,55 @@ describe("MockedFilesystemTests", () => { }); it("should tolerate absence of .nodejsapp directory", () => { - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("nodejsapps")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("nodejsapps")) { return false; } - if (path.endsWith(".nodejsapp")) { + if (path.toString().endsWith(".nodejsapp")) { return false; } - if (path.endsWith("cics.xml")) { + if (path.toString().endsWith("cics.xml")) { return false; } - if (path.endsWith(".profile")) { + if (path.toString().endsWith(".profile")) { return false; } - if (path.endsWith(".zosattributes")) { + if (path.toString().endsWith(".zosattributes")) { return false; } return true; }); // Mocks for the Nodejsapp - META-INF writable & nodejsapp dir creatable - jest.spyOn(fs, "accessSync").mockReturnValue(true); +// TODO this returns void so what's the point in spying +// jest.spyOn(fs, "accessSync").mockReturnValue(true); - let err: Error; try { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, false); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.prepareForSave(); } catch (error) { - err = error; + fail(error); } - - // Check the output as JSON - expect(err).toBeUndefined(); - }); + } ); it("should detect inability to create .nodejsapp directory", () => { - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("nodejsapps")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("nodejsapps")) { return false; } - if (path.endsWith("cics.xml")) { + if (path.toString().endsWith("cics.xml")) { return false; } - if (path.endsWith(".zosattributes")) { + if (path.toString().endsWith(".zosattributes")) { return false; } return true; }); // Bundle dir is unwriteable, so nodejsapps can't be created - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith("ExampleBundle03")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("ExampleBundle03")) { throw new Error("Wibble"); } return true; @@ -192,6 +190,7 @@ describe("MockedFilesystemTests", () => { let err: Error; try { bund.prepareForSave(); + fail("Error expected"); } catch (error) { err = error; @@ -201,18 +200,18 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("cics-deploy requires write permission to: "); }); it("should detect unwritable nodejsapps directory", () => { - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } - if (path.endsWith(".zosattributes")) { + if (path.toString().endsWith(".zosattributes")) { return false; } return true; }); - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith("nodejsapps")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("nodejsapps")) { throw new Error("Wibble"); } return true; @@ -225,6 +224,7 @@ describe("MockedFilesystemTests", () => { let err: Error; try { bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -236,21 +236,23 @@ describe("MockedFilesystemTests", () => { }); it("should complain if existing .nodejsapp file isn't overwritable", () => { // manifest don't exist, everying else does (inlucde .nodejsapp) - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } return true; }); // Mocks for the Nodejsapp - META-INF writable & nodejsapp dir creatable - jest.spyOn(fs, "accessSync").mockReturnValue(true); +// TODO why mock a void method? +// jest.spyOn(fs, "accessSync").mockReturnValue(true); let err: Error; try { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, false); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -261,15 +263,15 @@ describe("MockedFilesystemTests", () => { }); it("should complain if no write permission to existing .nodejsapp", () => { // manifest don't exist, everying else does (inlucde .nodejsapp) - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } return true; }); - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith(".nodejsapp")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".nodejsapp")) { throw new Error("Wibble"); } return true; @@ -281,6 +283,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -292,15 +295,15 @@ describe("MockedFilesystemTests", () => { }); it("should complain if no write permission to existing .profile", () => { // manifest don't exist, everying else does - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } return true; }); - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith(".profile")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".profile")) { throw new Error("Wibble"); } return true; @@ -311,6 +314,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -322,21 +326,21 @@ describe("MockedFilesystemTests", () => { }); it("should complain if no overwrite permission for existing .zosattributes", () => { - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } - if (path.endsWith(".nodejsapp")) { + if (path.toString().endsWith(".nodejsapp")) { return false; } - if (path.endsWith(".profile")) { + if (path.toString().endsWith(".profile")) { return false; } return true; }); - jest.spyOn(fs, "accessSync").mockImplementation((path: string) => { - if (path.endsWith(".zosattributes")) { + jest.spyOn(fs, "accessSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".zosattributes")) { throw new Error("Wibble"); } return true; @@ -347,6 +351,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, false); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.prepareForSave(); + fail("Expected error"); } catch (error) { err = error; @@ -356,15 +361,16 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain(".zosattributes already exists. Specify --overwrite to replace it."); }); it("should complain if can't make a new META-INF directory", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); +// TODO why mock a void? +// jest.spyOn(fs, "accessSync").mockReturnValue(true); // manifest don't exist, everying else does - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("META-INF")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("META-INF")) { return false; } return true; }); - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { + jest.spyOn(fs, "writeFileSync").mockImplementation((file: fs.PathOrFileDescriptor) => { return true; }); @@ -374,6 +380,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, true); bund.save(); + fail("Expected error"); } catch (error) { err = error; @@ -385,18 +392,19 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should complain if writing the manifest fails", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); +// TODO why mock void? +// jest.spyOn(fs, "accessSync").mockReturnValue(true); // manifest don't exist, everying else does - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("cics.xml")) { return false; } return true; }); // Mocks for the manifest - manifest write - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { - if (path.endsWith("cics.xml")) { + jest.spyOn(fs, "writeFileSync").mockImplementation((path: fs.PathOrFileDescriptor) => { + if (path.toString().endsWith("cics.xml")) { throw new Error("InjectedError"); } }); @@ -406,6 +414,7 @@ describe("MockedFilesystemTests", () => { try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, true); bund.save(); + fail("Expected error"); } catch (error) { err = error; @@ -417,14 +426,14 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should complain if creating nodejsapps dir fails", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith("nodejsapps")) { +// jest.spyOn(fs, "accessSync").mockReturnValue(true); + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith("nodejsapps")) { return false; } return true; }); - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { + jest.spyOn(fs, "writeFileSync").mockImplementation((path: fs.PathOrFileDescriptor) => { return true; }); @@ -435,6 +444,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.save(); + fail("Error expected"); } catch (error) { err = error; @@ -446,15 +456,15 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should complain if writing .nodejsapp file fails", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith(".nodejsapp")) { + // jest.spyOn(fs, "accessSync").mockReturnValue(true); + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".nodejsapp")) { return false; } return true; }); - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { - if (path.endsWith(".nodejsapp")) { + jest.spyOn(fs, "writeFileSync").mockImplementation((path: fs.PathOrFileDescriptor) => { + if (path.toString().endsWith(".nodejsapp")) { throw new Error("InjectedError"); } }); @@ -464,6 +474,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.save(); + fail("Expected error"); } catch (error) { err = error; @@ -475,16 +486,16 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should complain if writing .profile fails", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith(".profile")) { + // jest.spyOn(fs, "accessSync").mockReturnValue(true); + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".profile")) { return false; } return true; }); - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { - if (path.endsWith(".profile")) { + jest.spyOn(fs, "writeFileSync").mockImplementation((path: fs.PathOrFileDescriptor) => { + if (path.toString().endsWith(".profile")) { throw new Error("InjectedError"); } }); @@ -494,6 +505,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.save(); + fail("Error expected"); } catch (error) { err = error; @@ -505,17 +517,17 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should complain if writing .zosattributes fails", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); - jest.spyOn(fs, "existsSync").mockImplementation((path: string) => { - if (path.endsWith(".zosattributes")) { + // jest.spyOn(fs, "accessSync").mockReturnValue(true); + jest.spyOn(fs, "existsSync").mockImplementation((path: fs.PathLike) => { + if (path.toString().endsWith(".zosattributes")) { return false; } return true; }); // Mocks for the nodejsapp - write .zosattributes - jest.spyOn(fs, "writeFileSync").mockImplementation((path: string) => { - if (path.endsWith(".zosattributes")) { + jest.spyOn(fs, "writeFileSync").mockImplementation((path: fs.PathOrFileDescriptor) => { + if (path.toString().endsWith(".zosattributes")) { throw new Error("InjectedError"); } }); @@ -525,6 +537,7 @@ describe("MockedFilesystemTests", () => { const bund = new Bundle("__tests__/__resources__/ExampleBundle03", false, true); bund.addNodejsappDefinition("NodeName", "__tests__/__resources__/ExampleBundle03/Artefact1", 1000); bund.save(); + fail("Error expected"); } catch (error) { err = error; @@ -536,16 +549,17 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("InjectedError"); }); it("should know if the bundle is valid", () => { - jest.spyOn(fs, "accessSync").mockReturnValue(true); + // jest.spyOn(fs, "accessSync").mockReturnValue(true); jest.spyOn(fs, "existsSync").mockReturnValue(false); - jest.spyOn(fs, "writeFileSync").mockReturnValue(true); - jest.spyOn(fs, "mkdirSync").mockReturnValue(true); + // jest.spyOn(fs, "writeFileSync").mockReturnValue(true); + // jest.spyOn(fs, "mkdirSync").mockReturnValue(true); let err: Error; let bund; try { bund = new Bundle("__tests__/__resources__/ExampleBundle01", false, false); bund.validate(); + fail("Error expected"); } catch (error) { err = error; @@ -555,16 +569,15 @@ describe("MockedFilesystemTests", () => { expect(err.message).toContain("No bundle manifest file found"); expect(err.message).toContain("cics.xml"); - err = undefined; try { bund.save(); bund.validate(); + fail("Error expected"); } catch (error) { err = error; } - expect(err).toBeUndefined(); }); it("should complain if exceptions are thrown during manifest parsing", () => { @@ -574,6 +587,7 @@ describe("MockedFilesystemTests", () => { let err: Error; try { const bund = new Bundle("__tests__/__resources__/ExampleBundle01", true, true); + fail("Error expected"); } catch (error) { err = error; diff --git a/__tests__/api/BundleDeploy/BundleDeployer.test.ts b/__tests__/api/BundleDeploy/BundleDeployer.test.ts index b83f4ac0..81927cfa 100644 --- a/__tests__/api/BundleDeploy/BundleDeployer.test.ts +++ b/__tests__/api/BundleDeploy/BundleDeployer.test.ts @@ -10,9 +10,10 @@ */ import { BundleDeployer } from "../../../src/api/BundleDeploy/BundleDeployer"; -import { IHandlerParameters, TaskStage } from "@zowe/imperative"; +import { IHandlerParameters, ProfileInfo, TaskStage } from "@zowe/imperative"; import * as DeployBundleDefinition from "../../../src/cli/deploy/bundle/DeployBundle.definition"; import { ZosmfSession, SubmitJobs, List } from "@zowe/cli"; +import { Readable } from "stream"; const DEFAULT_PARAMTERS: IHandlerParameters = { @@ -21,14 +22,6 @@ const DEFAULT_PARAMTERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "deploy", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - if (profileError === true) { - throw new Error("Profile Error"); - } - return { host: "testname", user: "testuser", password: "testpwd" }; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { @@ -55,10 +48,11 @@ const DEFAULT_PARAMTERS: IHandlerParameters = { definition: DeployBundleDefinition.DeployBundleDefinition, fullDefinition: DeployBundleDefinition.DeployBundleDefinition, positionals: [], + stdin: new Readable() }; -let createSpy = jest.spyOn(ZosmfSession, "createBasicZosmfSession").mockImplementation(() => ({})); +let createSpy = jest.spyOn(ProfileInfo, "createSession").mockImplementation(() => ({})); let listSpy = jest.spyOn(List, "allMembers").mockImplementation(() => ({})); let submitSpy = jest.spyOn(SubmitJobs, "submitJclString").mockImplementation(() => ({})); let profileError = false; diff --git a/__tests__/api/BundlePush/BundlePusher.test.ts b/__tests__/api/BundlePush/BundlePusher.test.ts index 8a9deb0c..4f1968e9 100644 --- a/__tests__/api/BundlePush/BundlePusher.test.ts +++ b/__tests__/api/BundlePush/BundlePusher.test.ts @@ -13,7 +13,6 @@ import { BundlePusher } from "../../../src/api/BundlePush/BundlePusher"; import { IHandlerParameters, ImperativeError, IImperativeError, IProfile, Session } from "@zowe/imperative"; import * as cmci from "@zowe/cics-for-zowe-cli"; import * as PushBundleDefinition from "../../../src/cli/push/bundle/PushBundle.definition"; -import * as fse from "fs-extra"; import * as fs from "fs"; import { ZosmfSession, SshSession, SubmitJobs, Shell, List, Upload, Create } from "@zowe/cli"; @@ -23,25 +22,6 @@ const DEFAULT_PARAMTERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "push", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - - if (profileError === true) { - throw new Error("Profile Error"); - } - - if (type === "zosmf") { - return zosmfProfile; - } - if (type === "ssh") { - return sshProfile; - } - if (type === "cics") { - return cicsProfile; - } - return {}; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { diff --git a/__tests__/cli/deploy/bundle/DeployBundle.handler.test.ts b/__tests__/cli/deploy/bundle/DeployBundle.handler.test.ts index fef07be1..7f66055c 100644 --- a/__tests__/cli/deploy/bundle/DeployBundle.handler.test.ts +++ b/__tests__/cli/deploy/bundle/DeployBundle.handler.test.ts @@ -13,52 +13,43 @@ import {IHandlerParameters, ImperativeError} from "@zowe/imperative"; import * as DeployBundleDefinition from "../../../../src/cli/deploy/bundle/DeployBundle.definition"; import * as DeployBundleHandler from "../../../../src/cli/deploy/bundle/DeployBundle.handler"; +import { Readable } from "stream"; process.env.FORCE_COLOR = "0"; const DEFAULT_PARAMETERS: IHandlerParameters = { - arguments: { - $0: "bright", - _: ["zowe-cli-cics-deploy-plugin", "deploy", "bundle"], - silent: true + arguments: { + $0: "bright", + _: ["zowe-cli-cics-deploy-plugin", "deploy", "bundle"], + silent: true + }, + response: { + data: { + setMessage: jest.fn((setMsgArgs) => { + expect("" + setMsgArgs).toMatchSnapshot(); + }), + setObj: jest.fn((setObjArgs) => { + expect(setObjArgs).toMatchSnapshot(); + }) }, - profiles: { - get: (type: string) => { - if (type === "cics-deploy") { - return undefined; - } - if (type === "zosmf") { - return undefined; - } - return {}; - } - } as any, - response: { - data: { - setMessage: jest.fn((setMsgArgs) => { - expect("" + setMsgArgs).toMatchSnapshot(); - }), - setObj: jest.fn((setObjArgs) => { - expect(setObjArgs).toMatchSnapshot(); - }) - }, - console: { - log: jest.fn((logs) => { - expect("" + logs).toMatchSnapshot(); - }), - error: jest.fn((errors) => { - expect("" + errors).toMatchSnapshot(); - }), - errorHeader: jest.fn(() => undefined) - }, - progress: { - startBar: jest.fn((parms) => undefined), - endBar: jest.fn(() => undefined) - } - } as any, - definition: DeployBundleDefinition.DeployBundleDefinition, - fullDefinition: DeployBundleDefinition.DeployBundleDefinition, - positionals: [], + console: { + log: jest.fn((logs) => { + expect("" + logs).toMatchSnapshot(); + }), + error: jest.fn((errors) => { + expect("" + errors).toMatchSnapshot(); + }), + errorHeader: jest.fn(() => { ; }) + }, + progress: { + startBar: jest.fn((parms) => { ; }), + endBar: jest.fn(() => { ; }) + } + } as any, + definition: DeployBundleDefinition.DeployBundleDefinition, + fullDefinition: DeployBundleDefinition.DeployBundleDefinition, + positionals: [], + stdin: new Readable() }; describe("bundle Handler", () => { @@ -78,6 +69,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -102,6 +94,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -134,6 +127,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -152,6 +146,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -173,6 +168,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -194,6 +190,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -216,6 +213,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -231,6 +229,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -252,6 +251,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -273,6 +273,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -300,6 +301,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -324,6 +326,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -348,6 +351,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -384,6 +388,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -406,6 +411,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -422,6 +428,7 @@ describe("bundle Handler", () => { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -446,7 +453,7 @@ function setCommonParmsForNameTests(parms: IHandlerParameters) { parms.arguments.description = undefined; } -async function testNameError(name: string, result: string) { +async function testNameError(name: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForNameTests(params); params.arguments.name = name; @@ -455,6 +462,7 @@ async function testNameError(name: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -466,7 +474,7 @@ function setCommonParmsForBundledirTests(parms: IHandlerParameters) { parms.arguments.name = "WIBBLE"; } -async function testBundledirError(bundledir: string, result: string) { +async function testBundledirError(bundledir: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForBundledirTests(params); params.arguments.bundledir = bundledir; @@ -475,6 +483,7 @@ async function testBundledirError(bundledir: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -495,6 +504,7 @@ async function testProfileError(profile: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -515,6 +525,7 @@ async function testCicsplexError(cicsplex: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -536,6 +547,7 @@ async function testScopeError(scope: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -556,6 +568,7 @@ async function testCsdgroupError(csdgroup: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -575,6 +588,7 @@ async function testResgroupError(resgroup: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -594,6 +608,7 @@ async function testDescriptionError(description: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -614,6 +629,7 @@ async function testTimeoutError(timeout: number, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -624,7 +640,7 @@ function setCommonParmsForCicsHLQTests(parms: IHandlerParameters) { setCommonParmsForTimeoutTests(parms); } -async function testCicsHLQError(cicshlq: string, result: string) { +async function testCicsHLQError(cicshlq: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForCicsHLQTests(params); params.arguments.cicshlq = cicshlq; @@ -633,6 +649,7 @@ async function testCicsHLQError(cicshlq: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -644,7 +661,7 @@ function setCommonParmsForCpsmHLQTests(parms: IHandlerParameters) { parms.arguments.cicshlq = "WIBB.LE"; } -async function testCpsmHLQError(cpsmhlq: string, result: string) { +async function testCpsmHLQError(cpsmhlq: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForCpsmHLQTests(params); params.arguments.cpsmhlq = cpsmhlq; @@ -653,6 +670,7 @@ async function testCpsmHLQError(cpsmhlq: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -665,7 +683,7 @@ function setCommonParmsForJobcardTests(parms: IHandlerParameters) { parms.arguments.targetstate = "ENABLED"; } -async function testJobcardError(jobcard: string, result: string) { +async function testJobcardError(jobcard: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForJobcardTests(params); params.arguments.jobcard = jobcard; @@ -674,6 +692,7 @@ async function testJobcardError(jobcard: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -685,7 +704,7 @@ function setCommonParmsForTargetStateTests(parms: IHandlerParameters) { parms.arguments.targetstate = undefined; } -async function testTargetStateDeployError(targetstate: string, result: string) { +async function testTargetStateDeployError(targetstate: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForTargetStateTests(params); params.arguments.targetstate = targetstate; @@ -694,6 +713,7 @@ async function testTargetStateDeployError(targetstate: string, result: string) { try { const handler = new DeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } diff --git a/__tests__/cli/generate/bundle/GenerateBundle.handler.test.ts b/__tests__/cli/generate/bundle/GenerateBundle.handler.test.ts index 9a6ea11e..e9edd7fe 100644 --- a/__tests__/cli/generate/bundle/GenerateBundle.handler.test.ts +++ b/__tests__/cli/generate/bundle/GenerateBundle.handler.test.ts @@ -15,6 +15,7 @@ import {IHandlerParameters, Imperative, ImperativeError} from "@zowe/imperative" import * as GenerateBundleDefinition from "../../../../src/cli/generate/bundle/GenerateBundle.definition"; import * as GenerateBundleHandler from "../../../../src/cli/generate/bundle/GenerateBundle.handler"; import * as fs from "fs"; +import { Readable } from "stream"; process.env.FORCE_COLOR = "0"; @@ -24,11 +25,6 @@ const DEFAULT_PARAMTERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "generate", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - return {}; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { @@ -45,16 +41,17 @@ const DEFAULT_PARAMTERS: IHandlerParameters = { error: jest.fn((errors) => { expect("" + errors).toMatch("NO ERROR MESSAGE IS EXPECTED"); }), - errorHeader: jest.fn(() => undefined) + errorHeader: jest.fn(() => { ; }) }, progress: { - startBar: jest.fn((parms) => undefined), - endBar: jest.fn(() => undefined) + startBar: jest.fn((parms) => { ; }), + endBar: jest.fn(() => { ; }) } } as any, definition: GenerateBundleDefinition.GenerateBundleDefinition, fullDefinition: GenerateBundleDefinition.GenerateBundleDefinition, positionals: [], + stdin: new Readable() }; let consoleText = ""; @@ -128,8 +125,9 @@ describe("bundle Handler", () => { }); it("should produce the correct messages when overwrite on", async () => { DEFAULT_PARAMTERS.arguments.nosave = "false"; - jest.spyOn(fs, "writeFileSync").mockReturnValue(true); - jest.spyOn(fs, "mkdirSync").mockReturnValue(true); + // TODO why spy on a void method? + // jest.spyOn(fs, "writeFileSync").mockReturnValue(true); + // jest.spyOn(fs, "mkdirSync").mockReturnValue(true); const currentDir = process.cwd(); process.chdir("__tests__/__resources__/ExampleBundle04"); @@ -157,8 +155,9 @@ describe("bundle Handler", () => { it("should produce the correct messages when merge on", async () => { DEFAULT_PARAMTERS.arguments.nosave = "false"; DEFAULT_PARAMTERS.arguments.merge = "true"; - jest.spyOn(fs, "writeFileSync").mockReturnValue(true); - jest.spyOn(fs, "mkdirSync").mockReturnValue(true); + // TODO why spy on a void method? + // jest.spyOn(fs, "writeFileSync").mockReturnValue(true); + // jest.spyOn(fs, "mkdirSync").mockReturnValue(true); const currentDir = process.cwd(); process.chdir("__tests__/__resources__/ExampleBundle05"); diff --git a/__tests__/cli/push/bundle/PushBundle.handler.test.ts b/__tests__/cli/push/bundle/PushBundle.handler.test.ts index a2070ca9..4540bdc7 100644 --- a/__tests__/cli/push/bundle/PushBundle.handler.test.ts +++ b/__tests__/cli/push/bundle/PushBundle.handler.test.ts @@ -13,6 +13,7 @@ import {IHandlerParameters, ImperativeError} from "@zowe/imperative"; import * as PushBundleDefinition from "../../../../src/cli/push/bundle/PushBundle.definition"; import * as PushBundleHandler from "../../../../src/cli/push/bundle/PushBundle.handler"; +import { Readable } from "stream"; process.env.FORCE_COLOR = "0"; @@ -22,17 +23,6 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "push", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - if (type === "cics-deploy") { - return undefined; - } - if (type === "zosmf") { - return undefined; - } - return {}; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { @@ -49,16 +39,17 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { error: jest.fn((errors) => { expect("" + errors).toMatchSnapshot(); }), - errorHeader: jest.fn(() => undefined) + errorHeader: jest.fn(() => { ; }) }, progress: { - startBar: jest.fn((parms) => undefined), - endBar: jest.fn(() => undefined) + startBar: jest.fn((parms) => { ; }), + endBar: jest.fn(() => { ; }) } } as any, definition: PushBundleDefinition.PushBundleDefinition, fullDefinition: PushBundleDefinition.PushBundleDefinition, positionals: [], + stdin: new Readable() }; describe("bundle Handler", () => { @@ -99,6 +90,7 @@ async function testError(parms: IHandlerParameters, result: string) { try { const handler = new PushBundleHandler.default(); await handler.process(parms); + fail("Expected error"); } catch (e) { err = e; } diff --git a/__tests__/cli/undeploy/bundle/UndeployBundle.handler.test.ts b/__tests__/cli/undeploy/bundle/UndeployBundle.handler.test.ts index ee564c1c..12d09d50 100644 --- a/__tests__/cli/undeploy/bundle/UndeployBundle.handler.test.ts +++ b/__tests__/cli/undeploy/bundle/UndeployBundle.handler.test.ts @@ -14,7 +14,7 @@ import {CheckStatus, ZosmfSession} from "@zowe/cli"; import {IHandlerParameters, Imperative, ImperativeError} from "@zowe/imperative"; import * as UndeployBundleDefinition from "../../../../src/cli/undeploy/bundle/UndeployBundle.definition"; import * as UndeployBundleHandler from "../../../../src/cli/undeploy/bundle/UndeployBundle.handler"; -import * as fs from "fs"; +import { Readable } from "stream"; process.env.FORCE_COLOR = "0"; @@ -24,11 +24,6 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { _: ["zowe-cli-cics-deploy-plugin", "undeploy", "bundle"], silent: true }, - profiles: { - get: (type: string) => { - return {}; - } - } as any, response: { data: { setMessage: jest.fn((setMsgArgs) => { @@ -55,6 +50,7 @@ const DEFAULT_PARAMETERS: IHandlerParameters = { definition: UndeployBundleDefinition.UndeployBundleDefinition, fullDefinition: UndeployBundleDefinition.UndeployBundleDefinition, positionals: [], + stdin: new Readable() }; describe("bundle Handler", () => { @@ -68,6 +64,7 @@ describe("bundle Handler", () => { try { const handler = new UndeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -93,6 +90,7 @@ describe("bundle Handler", () => { try { const handler = new UndeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } @@ -122,7 +120,7 @@ function setCommonParmsForTargetStateTests(parms: IHandlerParameters) { parms.arguments.jobcard = undefined; } -async function testTargetStateUndeployError(targetstate: string, result: string) { +async function testTargetStateUndeployError(targetstate: string | undefined, result: string) { const params = Object.assign({}, ...[DEFAULT_PARAMETERS]); setCommonParmsForTargetStateTests(params); params.arguments.targetstate = targetstate; @@ -131,6 +129,7 @@ async function testTargetStateUndeployError(targetstate: string, result: string) try { const handler = new UndeployBundleHandler.default(); await handler.process(params); + fail("Expected error"); } catch (e) { err = e; } diff --git a/__tests__/imperative.test.ts b/__tests__/imperative.test.ts index dde2f175..99f21b98 100644 --- a/__tests__/imperative.test.ts +++ b/__tests__/imperative.test.ts @@ -17,7 +17,6 @@ describe("imperative config", () => { it("config should match expected values", () => { const config = require("../src/imperative"); expect(config.name).toBe("cics-deploy"); - expect(config.pluginHealthCheck).toContain("healthCheck.handler"); expect(config.pluginSummary).toBe("Generate and deploy IBM CICS bundle resources"); expect(config.productDisplayName).toBe("Zowe cics-deploy plug-in"); expect(config.rootCommandDescription).toContain("CICS bundle deployment plugin."); diff --git a/gulp/GenerateDoc.ts b/gulp/GenerateDoc.ts index 3b762889..2e4b4593 100644 --- a/gulp/GenerateDoc.ts +++ b/gulp/GenerateDoc.ts @@ -44,7 +44,8 @@ const doc: ITaskFunction = async () => { myConfig.loadedConfig.commandModuleGlobs = ["src/cli/*/*.definition!(.d).*s"]; // Need to set this for the internal caller location so that the commandModuleGlobs finds the commands - process.mainModule.filename = __dirname + "/../package.json"; + if(require.main === undefined) throw new Error("main is undefined"); + require.main.filename = __dirname + "/../package.json"; await Imperative.init(myConfig.loadedConfig); const loadedDefinitions = Imperative.fullCommandTree; @@ -91,7 +92,7 @@ const doc: ITaskFunction = async () => { function getFilteredChildren(root: ICommandDefinition) { const allDefSoFar: string[] = []; const cmdNamesToRemove = ["config", "plugins"]; - const filteredChildren = root.children.sort((a, b) => a.name.localeCompare(b.name)).filter((cmdDef) => { + const filteredChildren = root.children?.sort((a, b) => a.name.localeCompare(b.name)).filter((cmdDef) => { if (cmdNamesToRemove.indexOf(cmdDef.name) !== -1) { return false; } @@ -100,7 +101,7 @@ const doc: ITaskFunction = async () => { return true; } return false; - }); + }) || []; return filteredChildren; } diff --git a/package.json b/package.json index c0f23cc6..f612d1e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zowe-cli-cics-deploy-plugin", - "version": "1.1.1", + "version": "2.0.0", "description": "IBM CICS Bundle generation and deployment for Zowe CLI", "repository": { "type": "git", @@ -28,7 +28,8 @@ "zowe-cli-cics-deploy": "./lib/main.js" }, "scripts": { - "build": "tsc --pretty && npm run checkTestsCompile && gulp doc", + "build": "tsc --pretty && npm run checkTestsCompile", + "build_bak": "tsc --pretty && npm run checkTestsCompile && gulp doc", "checkTestsCompile": "echo \"Checking that test source compiles...\" && tsc --project __tests__/test-tsconfig.json --noEmit ", "prebuild": "npm run clean && npm run lint && echo Using TypeScript && tsc --version", "clean": "rimraf lib", @@ -45,51 +46,55 @@ "configurationModule": "lib/imperative.js" }, "dependencies": { - "@zowe/cics-for-zowe-cli": "^4.0.8", - "fast-xml-parser": "^4.2.4" + "@zowe/cics-for-zowe-cli": "^6.7.0", + "@zowe/zowe-explorer-api": "^3.2.0", + "fast-xml-parser": "^5.2.3" }, "devDependencies": { - "@zowe/cli": "^6.0.0", - "@zowe/imperative": "^4.7.3", - "@types/fs-extra": "^8.0.1", - "@types/jest": "^22.2.3", - "@types/node": "^12.12.24", - "@types/yargs": "^13.0.4", - "clear-require": "^2.0.0", - "env-cmd": "^8.0.2", - "fast-xml-parser": "^4.2.4", - "fs-extra": "^8.1.0", - "gulp": "^4.0.2", - "gulp-cli": "^2.2.1", - "gulp-debug": "^4.0.0", + "@types/fs-extra": "^11.0.4", + "@types/jest": "^29.5.14", + "@types/node": "^22.15.21", + "@types/yargs": "^17.0.33", + "@zowe/cli": "^8.21.0", + "@zowe/imperative": "^8.21.0", + "clear-require": "^3.0.0", + "env-cmd": "^10.1.0", + "fast-xml-parser": "^5.2.3", + "fs-extra": "^11.3.0", + "gulp": "^5.0.0", + "gulp-cli": "^3.0.0", + "gulp-debug": "^5.0.1", "gulp-plumber": "^1.2.1", - "gulp-replace": "^1.0.0", + "gulp-replace": "^1.1.4", "gulp-util": "^3.0.8", - "jest": "^26.0.1", - "jest-cli": "^26.0.1", - "jest-environment-node": "^26.0.1", + "jest": "^29.7.0", + "jest-cli": "^29.7.0", + "jest-environment-node": "^29.7.0", "jest-environment-node-debug": "^2.0.0", - "jest-html-reporter": "^3.1.3", - "jest-junit": "^10.0.0", - "js-yaml": "^3.14.0", - "mustache": "^4.0.1", - "rimraf": "^3.0.2", - "ts-jest": "^26.1.0", - "ts-node": "^8.10.2", - "tslint": "^6.1.2", - "typedoc": "^0.17.7", - "typescript": "^3.9.5", - "uuid": "^3.3.2" + "jest-html-reporter": "^4.1.0", + "jest-junit": "^16.0.0", + "js-yaml": "^4.1.0", + "mustache": "^4.2.0", + "rimraf": "^6.0.1", + "ts-jest": "^29.3.4", + "ts-node": "^10.9.2", + "tslint": "^6.1.3", + "typedoc": "^0.28.4", + "typescript": "^5.8.3", + "uuid": "^11.1.0" }, "peerDependencies": { - "@zowe/cli": "^6.0.0", - "@zowe/imperative": "^4.7.3" + "@zowe/cli": "^8.0.0", + "@zowe/imperative": "^8.0.0" }, "jest": { "modulePathIgnorePatterns": [ "__tests__/__snapshots__/" ], - "reporters": [ "default", "jest-junit" ], + "reporters": [ + "default", + "jest-junit" + ], "transform": { ".(ts)": "ts-jest" }, diff --git a/src/api/BundleDeploy/BundleDeployer.ts b/src/api/BundleDeploy/BundleDeployer.ts index 41013f27..24b96971 100644 --- a/src/api/BundleDeploy/BundleDeployer.ts +++ b/src/api/BundleDeploy/BundleDeployer.ts @@ -12,8 +12,8 @@ "use strict"; import { IHandlerParameters, Logger, ImperativeError, AbstractSession, ITaskWithStatus, - TaskStage , TaskProgress} from "@zowe/imperative"; -import { ZosmfSession, SubmitJobs, List } from "@zowe/cli"; + TaskStage , TaskProgress, ProfileInfo} from "@zowe/imperative"; +import { SubmitJobs, List } from "@zowe/cli"; import { ParmValidator } from "./ParmValidator"; import * as path from "path"; import { ZosmfConfig } from "../BundlePush/ZosmfConfig"; @@ -223,23 +223,30 @@ export class BundleDeployer { return jcl; } - private async createZosMFSession(): Promise { - // Create a zosMF session - let zosmfProfile; - try { - zosmfProfile = this.params.profiles.get("zosmf"); - } - catch (error) { - // No-op, we can cope with there being no profile. - } - - if (zosmfProfile === undefined) { - zosmfProfile = {}; - } - - ZosmfConfig.mergeProfile(zosmfProfile, this.params); - - return ZosmfSession.createBasicZosmfSession(zosmfProfile); + private async createZosMFSession(): Promise { + const profInfo = new ProfileInfo("zowe"); + await profInfo.readProfilesFromDisk(); + const zosmfProfAttrs = profInfo.getDefaultProfile("zosmf"); + const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true }); + return ProfileInfo.createSession(zosmfMergedArgs.knownArgs); + + // TODO - we've lost the concept of merging params with our default profile ... was that important? + // // Create a zosMF session + // let zosmfProfile; + // try { + // zosmfProfile = this.params.profiles.get("zosmf"); + // } + // catch (error) { + // // No-op, we can cope with there being no profile. + // } + + // if (zosmfProfile === undefined) { + // zosmfProfile = {}; + // } + + // ZosmfConfig.mergeProfile(zosmfProfile, this.params); + + // return ZosmfSession.createSessCfgFromArgs(zosmfProfile); } private async checkHLQDatasets(session: any) { diff --git a/src/api/BundleDeploy/ParmValidator.ts b/src/api/BundleDeploy/ParmValidator.ts index 33aa11bc..63f97d6a 100644 --- a/src/api/BundleDeploy/ParmValidator.ts +++ b/src/api/BundleDeploy/ParmValidator.ts @@ -11,7 +11,7 @@ "use strict"; -import { IHandlerParameters, Logger } from "@zowe/imperative"; +import { IHandlerParameters, ProfileInfo } from "@zowe/imperative"; export class ParmValidator { @@ -91,7 +91,7 @@ export class ParmValidator { } } - private static validateCicsDeployProfile(params: IHandlerParameters) { + private static async validateCicsDeployProfile(params: IHandlerParameters) { // if missing, then CICSPlex and Scope must be set if (params.arguments["cics-deploy-profile"] === undefined) { @@ -111,12 +111,14 @@ export class ParmValidator { } // Now check that the profile can be found - const prof = params.profiles.get("cics-deploy"); + const profInfo = new ProfileInfo("zowe"); + await profInfo.readProfilesFromDisk(); + const prof = profInfo.getDefaultProfile("cics-deploy"); // const logger = Logger.getAppLogger(); // logger.debug("Profile: " + JSON.stringify(prof)); - if (prof === undefined) { + if (!prof) { throw new Error('cics-deploy-profile "' + params.arguments["cics-deploy-profile"] + '" not found.'); } } diff --git a/src/api/BundlePush/BundlePusher.ts b/src/api/BundlePush/BundlePusher.ts index 7ed4d0f5..2d4f67d4 100644 --- a/src/api/BundlePush/BundlePusher.ts +++ b/src/api/BundlePush/BundlePusher.ts @@ -11,8 +11,8 @@ "use strict"; -import { IHandlerParameters, AbstractSession, ITaskWithStatus, TaskStage, TaskProgress, Logger, IProfile, Session } from "@zowe/imperative"; -import { List, ZosmfSession, SshSession, Shell, Upload, IUploadOptions, ZosFilesAttributes, Create } from "@zowe/cli"; +import { IHandlerParameters, AbstractSession, ITaskWithStatus, TaskStage, TaskProgress, Logger, IProfile, ISession, Session, ProfileInfo } from "@zowe/imperative"; +import { List, ZosmfSession, SshSession, Shell, Upload, IUploadOptions, ZosFilesAttributes, Create, ISshSession } from "@zowe/cli"; import { getResource, IResourceParms } from "@zowe/cics-for-zowe-cli"; import { BundleDeployer } from "../BundleDeploy/BundleDeployer"; import { Bundle } from "../BundleContent/Bundle"; @@ -209,18 +209,12 @@ export class BundlePusher { } } - private getProfile(type: string): IProfile { - let profile; - try { - profile = this.params.profiles.get(type); - } - catch (error) { - // Tolerate errors - } - - if (profile === undefined) { - profile = {}; - } + private getProfile(type: string): Session { + const profInfo = new ProfileInfo("zowe"); + profInfo.readProfilesFromDisk(); + const zosmfProfAttrs = profInfo.getDefaultProfile(type); + const zosmfMergedArgs = profInfo.mergeArgsForProfile(zosmfProfAttrs, { getSecureVals: true }); + const profile = ProfileInfo.createSession(zosmfMergedArgs.knownArgs); return profile; } @@ -283,22 +277,30 @@ export class BundlePusher { } } - private async createZosMFSession(zosmfProfile: IProfile): Promise { - try { - return ZosmfSession.createBasicZosmfSession(zosmfProfile); - } - catch (error) { - throw new Error("Failure occurred creating a zosmf session: " + error.message); - } + private async createZosMFSession(zosmfProfile: IProfile): Promise { + const session: ISession = { + rejectUnauthorized: zosmfProfile.rejectUnauthorized, + basePath: zosmfProfile.basePath, + protocol: zosmfProfile.protocol ? zosmfProfile.protocol.toLowerCase() : 'https', + requestCompletionTimeout: isNaN(zosmfProfile.completionTimeout) ? undefined : zosmfProfile.completionTimeout, + socketConnectTimeout: isNaN(zosmfProfile.establishConnectionTimeout) ? undefined : zosmfProfile.establishConnectionTimeout, + user: zosmfProfile.user, + password: zosmfProfile.password, + }; + return new Session(session); } private async createSshSession(sshProfile: IProfile): Promise { - try { - return SshSession.createBasicSshSession(sshProfile); - } - catch (error) { - throw new Error("Failure occurred creating an ssh session: " + error.message); - } + const session: ISshSession = { + hostname: sshProfile.hostname, + port: sshProfile.port, + privateKey: sshProfile.privateKey, + keyPassphrase: sshProfile.keyPassphrase, + handshakeTimeout: isNaN(sshProfile.handshakeTimeout) ? undefined : sshProfile.handshakeTimeout, + user: sshProfile.user, + password: sshProfile.password, + }; + return new SshSession(session); } private async createCicsSession(cicsProfile: IProfile): Promise { diff --git a/src/cli/shared/BundleParent.handler.ts b/src/cli/shared/BundleParent.handler.ts index 100541b6..4e827415 100644 --- a/src/cli/shared/BundleParent.handler.ts +++ b/src/cli/shared/BundleParent.handler.ts @@ -93,7 +93,7 @@ export abstract class BundleParentHandler implements ICommandHandler { * @throws ImperativeError * @memberof BundleParentHandler */ - public abstract async performAction(params: IHandlerParameters): Promise; + public abstract performAction(params: IHandlerParameters): Promise; private replacePassword(source: string, pwd: string): string { if (pwd !== undefined) { diff --git a/src/healthCheck.handler.ts b/src/healthCheck.handler.ts deleted file mode 100644 index fbe5888f..00000000 --- a/src/healthCheck.handler.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* -* This program and the accompanying materials are made available under the terms of the -* Eclipse Public License v2.0 which accompanies this distribution, and is available at -* https://www.eclipse.org/legal/epl-v20.html -* -* SPDX-License-Identifier: EPL-2.0 -* -* Copyright Contributors to the Zowe Project. -* -*/ - -import {ICommandHandler, IHandlerParameters, Logger} from "@zowe/imperative"; - -export default class HealthCheckHandler implements ICommandHandler { - public async process(params: IHandlerParameters): Promise { - Logger.getImperativeLogger().debug("Invoked health check handler"); - params.response.console.log("You would report problems identified by healthCheck.\n" + - "This handler is not currently called by Imperative, but\n" + - "its existence prevents a warning during plugin validation." - ); - } -} diff --git a/src/imperative.ts b/src/imperative.ts index 03bf380d..099e94a9 100644 --- a/src/imperative.ts +++ b/src/imperative.ts @@ -18,7 +18,6 @@ const MAX_TARGETDIR_LENGTH = 255; const config: IImperativeConfig = { commandModuleGlobs: ["**/cli/*/*.definition!(.d).*s"], - pluginHealthCheck: __dirname + "/healthCheck.handler", pluginSummary: "Generate and deploy IBM CICS bundle resources", pluginAliases: ["cdep"], rootCommandDescription: "CICS bundle deployment plugin.", @@ -127,28 +126,10 @@ const config: IImperativeConfig = { required: true }, type: "string" - } - }, - required: ["cicsplex", "scope", "cics-hlq", "cpsm-hlq", "job-card"] - }, - createProfileExamples: [ - { - options: "example1 --cicsplex PLEX1 --scope TESTGRP1 --cics-hlq CICSTS55.CICS720 --cpsm-hlq CICSTS55.CPSM550", - description: "Create a cics-deploy profile called 'example1' to connect to a CPSM managed group of CICS regions " + - "within the TESTGRP1 scope of a cicsplex named PLEX1" - }, - { - options: "example2 --cicsplex PLEX1 --scope TESTGRP1 --cics-hlq CICSTS55.CICS720 --cpsm-hlq CICSTS55.CPSM550 --res-group BUNDGRP1", - description: "Create a cics-deploy profile called 'example2' to connect to the same CPSM managed group of regions, " + - "and identify a BAS resource group BUNDGRP1 in which to store resource definitions" + }, }, - { - options: "example3 --cicsplex PLEX1 --scope TESTGRP1 --cics-hlq CICSTS55.CICS720 " + - "--cpsm-hlq CICSTS55.CPSM550 --target-directory /var/cicsts/bundles", - description: "Create a cics-deploy profile called 'example3' to connect to the same CPSM managed group of regions, " + - "and identify the default USS directory to which bundles should be uploaded" - } - ] + required: ["cicsplex", "scope", "cics-hlq", "cpsm-hlq", "job-card"], + } } ] };