Skip to content

Commit 1e37f7e

Browse files
committed
detect npm errors
1 parent 1861348 commit 1e37f7e

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

__tests__/api/BundlePush/BundlePusher.test.ts

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,22 @@ describe("BundlePusher01", () => {
280280
expect(membersSpy).toHaveBeenCalledTimes(2);
281281
expect(submitSpy).toHaveBeenCalledTimes(1);
282282
});
283+
it("should tolerate delete of empty directory", async () => {
284+
shellSpy.mockImplementation((session: any, cmd: string, dir: string, stdoutHandler: (data: string) => void) => {
285+
stdoutHandler("Injected FSUM9195 empty directory message");
286+
});
287+
288+
await runPushTest("__tests__/__resources__/ExampleBundle01", true,
289+
"PUSH operation completed.");
290+
291+
expect(zosMFSpy).toHaveBeenCalledTimes(1);
292+
expect(sshSpy).toHaveBeenCalledTimes(1);
293+
expect(createSpy).toHaveBeenCalledTimes(1);
294+
expect(listSpy).toHaveBeenCalledTimes(1);
295+
expect(shellSpy).toHaveBeenCalledTimes(1);
296+
expect(membersSpy).toHaveBeenCalledTimes(2);
297+
expect(submitSpy).toHaveBeenCalledTimes(2);
298+
});
283299
it("should handle error with attribs file", async () => {
284300
existsSpy.mockImplementation((data: string) => {
285301
if (data.indexOf(".zosattributes") > -1) {
@@ -421,7 +437,8 @@ describe("BundlePusher01", () => {
421437
});
422438

423439
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
424-
"A problem occurred attempting to run 'npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
440+
"A problem occurred attempting to run 'export PATH=\"$PATH:/usr/lpp/IBM/cnj/IBM/node-latest-os390-s390x/bin\" " +
441+
"&& npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
425442
"Problem is: The output from the remote command implied that an error occurred.");
426443

427444
expect(consoleText).toContain("Injected stdout error message");
@@ -455,7 +472,8 @@ describe("BundlePusher01", () => {
455472
});
456473

457474
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
458-
"A problem occurred attempting to run 'npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
475+
"A problem occurred attempting to run 'export PATH=\"$PATH:/usr/lpp/IBM/cnj/IBM/node-latest-os390-s390x/bin\" " +
476+
"&& npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
459477
"Problem is: The output from the remote command implied that an error occurred.");
460478

461479
expect(consoleText).toContain("Injected FSUM7351 not found message");
@@ -470,6 +488,41 @@ describe("BundlePusher01", () => {
470488
expect(readSpy).toHaveBeenCalledTimes(1);
471489
expect(uploadSpy).toHaveBeenCalledTimes(1);
472490
});
491+
it("should handle failure of remote npm install with node error", async () => {
492+
shellSpy.mockImplementation((session: any, cmd: string, dir: string, stdoutHandler: (data: string) => void) => {
493+
if (cmd.indexOf("npm install") > -1) {
494+
stdoutHandler("Injected npm ERR! Exit status 1 message");
495+
}
496+
else {
497+
return true;
498+
}
499+
});
500+
existsSpy.mockImplementation((data: string) => {
501+
if (data.indexOf(".zosattributes") > -1) {
502+
return false;
503+
}
504+
if (data.indexOf("package.json") > -1) {
505+
return true;
506+
}
507+
});
508+
509+
await runPushTestWithError("__tests__/__resources__/ExampleBundle01", false,
510+
"A problem occurred attempting to run 'export PATH=\"$PATH:/usr/lpp/IBM/cnj/IBM/node-latest-os390-s390x/bin\" " +
511+
"&& npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
512+
"Problem is: The output from the remote command implied that an error occurred.");
513+
514+
expect(consoleText).toContain("Injected npm ERR! Exit status 1 message");
515+
expect(zosMFSpy).toHaveBeenCalledTimes(1);
516+
expect(sshSpy).toHaveBeenCalledTimes(1);
517+
expect(createSpy).toHaveBeenCalledTimes(1);
518+
expect(listSpy).toHaveBeenCalledTimes(1);
519+
expect(shellSpy).toHaveBeenCalledTimes(1);
520+
expect(membersSpy).toHaveBeenCalledTimes(0);
521+
expect(submitSpy).toHaveBeenCalledTimes(0);
522+
expect(existsSpy).toHaveBeenCalledTimes(2);
523+
expect(readSpy).toHaveBeenCalledTimes(1);
524+
expect(uploadSpy).toHaveBeenCalledTimes(1);
525+
});
473526
it("should handle error with remote bundle deploy", async () => {
474527
submitSpy.mockImplementationOnce(() => { throw new Error("Injected deploy error"); });
475528

src/api/BundlePush/BundlePusher.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,27 @@ export class BundlePusher {
292292

293293
private async runNpmInstall(sshSession: SshSession) {
294294
this.updateStatus("Running npm install for the remote bundle");
295-
await this.runSshCommandInRemoteDirectory(sshSession, this.params.arguments.bundledir, "npm install");
295+
296+
// Attempt to set the PATH for the default location of Node on z/OS. Note,
297+
// we might be able to improve this by looking for the location via the
298+
// architected .profile within the USSCONFIG structure.
299+
const setNodehomeCmd = "export PATH=\"$PATH:/usr/lpp/IBM/cnj/IBM/node-latest-os390-s390x/bin\"";
300+
await this.runSshCommandInRemoteDirectory(sshSession, this.params.arguments.bundledir, setNodehomeCmd + " && npm install");
296301
}
297302

298303
private async runSshCommandInRemoteDirectory(sshSession: SshSession, directory: string, sshCommand: string) {
299304
try {
300305
this.sshOutputText = "";
301306
const shell = await Shell.executeSshCwd(sshSession, sshCommand, directory, this.sshOutput.bind(this));
302307

303-
// Did the SSH command work? It's unclear how to tell, but for starters let's look for the word
304-
// 'error' in the output text.
305-
if (this.sshOutputText.toUpperCase().indexOf("ERROR ") > -1 ||
306-
this.sshOutputText.toUpperCase().indexOf("FSUM") > -1 ) {
308+
// Did the SSH command work? It's unclear how to tell, but for starters let's look for common
309+
// signifiers in the output text. Note that FSUM9195 implies that we've tried to delete an
310+
// empty directory - that's permitted.
311+
const upperCaseOutputText = this.sshOutputText.toUpperCase();
312+
if (upperCaseOutputText.indexOf("ERROR ") > -1 ||
313+
(upperCaseOutputText.indexOf("FSUM") > -1 &&
314+
upperCaseOutputText.indexOf("FSUM9195") === -1) ||
315+
upperCaseOutputText.indexOf("ERR!") > -1 ) {
307316
// if we've not already logged the output, log it now
308317
if (this.params.arguments.verbose !== true)
309318
{

0 commit comments

Comments
 (0)