@@ -30,29 +30,31 @@ const DEFAULT_PARAMTERS: IHandlerParameters = {
30
30
response : {
31
31
data : {
32
32
setMessage : jest . fn ( ( setMsgArgs ) => {
33
- expect ( " " + setMsgArgs ) . toMatchSnapshot ( ) ;
33
+ throw new Error ( "Unexpected use of setMessage in Mock: " + setMsgArgs . toString ( ) ) ;
34
34
} ) ,
35
35
setObj : jest . fn ( ( setObjArgs ) => {
36
- expect ( setObjArgs ) . toMatchSnapshot ( ) ;
36
+ throw new Error ( "Unexpected use of setObj in Mock: " + setObjArgs . toString ( ) ) ;
37
37
} )
38
38
} ,
39
39
console : {
40
40
log : jest . fn ( ( logs ) => {
41
- expect ( "" + logs ) . toMatchSnapshot ( ) ;
41
+ consoleText += logs . toString ( ) ;
42
42
} ) ,
43
43
error : jest . fn ( ( errors ) => {
44
- expect ( " " + errors ) . toMatchSnapshot ( ) ;
44
+ throw new Error ( "Unexpected use of error log in Mock: " + errors . toString ( ) ) ;
45
45
} ) ,
46
46
errorHeader : jest . fn ( ( ) => undefined )
47
47
} ,
48
48
progress : {
49
49
startBar : jest . fn ( ( parms ) => undefined ) ,
50
50
endBar : jest . fn ( ( ) => undefined )
51
- }
51
+ } ,
52
+ consoleText : ""
52
53
} as any ,
53
54
definition : PushBundleDefinition . PushBundleDefinition ,
54
55
fullDefinition : PushBundleDefinition . PushBundleDefinition ,
55
56
} ;
57
+ let consoleText = "" ;
56
58
57
59
// Initialise xml2json before mocking anything
58
60
const parser = require ( "xml2json" ) ;
@@ -87,6 +89,7 @@ describe("BundlePusher01", () => {
87
89
}
88
90
} ) ;
89
91
uploadSpy = jest . spyOn ( Upload , "dirToUSSDirRecursive" ) . mockImplementation ( ( ) => ( { } ) ) ;
92
+ consoleText = "" ;
90
93
} ) ;
91
94
afterEach ( ( ) => {
92
95
jest . restoreAllMocks ( ) ;
@@ -355,6 +358,40 @@ describe("BundlePusher01", () => {
355
358
expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
356
359
expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
357
360
} ) ;
361
+ it ( "should handle failure of remote npm install" , async ( ) => {
362
+ shellSpy . mockImplementation ( ( session : any , cmd : string , dir : string , stdoutHandler : ( data : string ) => void ) => {
363
+ if ( cmd . indexOf ( "npm install" ) > - 1 ) {
364
+ stdoutHandler ( "Injected stdout error message" ) ;
365
+ }
366
+ else {
367
+ return true ;
368
+ }
369
+ } ) ;
370
+ existsSpy . mockImplementation ( ( data : string ) => {
371
+ if ( data . indexOf ( ".zosattributes" ) > - 1 ) {
372
+ return false ;
373
+ }
374
+ if ( data . indexOf ( "package.json" ) > - 1 ) {
375
+ return true ;
376
+ }
377
+ } ) ;
378
+
379
+ await runPushTestWithError ( "__tests__/__resources__/ExampleBundle01" , false ,
380
+ "A problem occurred attempting to run 'npm install' in remote directory '/u/ThisDoesNotExist/12345678'. " +
381
+ "Problem is: The output from the remote command implied that an error occurred." ) ;
382
+
383
+ expect ( consoleText ) . toContain ( "Injected stdout error message" ) ;
384
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
385
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
386
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
387
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
388
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 1 ) ;
389
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 0 ) ;
390
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 0 ) ;
391
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 2 ) ;
392
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
393
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
394
+ } ) ;
358
395
it ( "should handle error with remote bundle deploy" , async ( ) => {
359
396
submitSpy . mockImplementationOnce ( ( ) => { throw new Error ( "Injected deploy error" ) ; } ) ;
360
397
@@ -388,6 +425,41 @@ describe("BundlePusher01", () => {
388
425
expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
389
426
expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
390
427
} ) ;
428
+ it ( "should run to completion with verbose output" , async ( ) => {
429
+ const parms = getCommonParmsForPushTests ( ) ;
430
+ parms . arguments . verbose = true ;
431
+ shellSpy . mockImplementation ( ( session : any , cmd : string , dir : string , stdoutHandler : ( data : string ) => void ) => {
432
+ stdoutHandler ( "Injected stdout shell message" ) ;
433
+ } ) ;
434
+ existsSpy . mockImplementation ( ( data : string ) => {
435
+ if ( data . indexOf ( ".zosattributes" ) > - 1 ) {
436
+ return false ;
437
+ }
438
+ if ( data . indexOf ( "package.json" ) > - 1 ) {
439
+ return true ;
440
+ }
441
+ } ) ;
442
+
443
+ await runPushTest ( "__tests__/__resources__/ExampleBundle01" , false , "PUSH operation completed." , parms ) ;
444
+
445
+ expect ( consoleText ) . toContain ( "Making remote bundle directory" ) ;
446
+ expect ( consoleText ) . toContain ( "Accessing contents of remote bundle directory" ) ;
447
+ expect ( consoleText ) . toContain ( "Uploading the bundle to the remote bundle directory" ) ;
448
+ expect ( consoleText ) . toContain ( "Running npm install for the remote bundle" ) ;
449
+ expect ( consoleText ) . toContain ( "Injected stdout shell message" ) ;
450
+ expect ( consoleText ) . toContain ( "Deploying the bundle to CICS" ) ;
451
+ expect ( consoleText ) . toContain ( "Deployed existing bundle to CICS" ) ;
452
+ expect ( zosMFSpy ) . toHaveBeenCalledTimes ( 1 ) ;
453
+ expect ( sshSpy ) . toHaveBeenCalledTimes ( 1 ) ;
454
+ expect ( listSpy ) . toHaveBeenCalledTimes ( 1 ) ;
455
+ expect ( createSpy ) . toHaveBeenCalledTimes ( 1 ) ;
456
+ expect ( shellSpy ) . toHaveBeenCalledTimes ( 1 ) ;
457
+ expect ( membersSpy ) . toHaveBeenCalledTimes ( 2 ) ;
458
+ expect ( submitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
459
+ expect ( existsSpy ) . toHaveBeenCalledTimes ( 2 ) ;
460
+ expect ( readSpy ) . toHaveBeenCalledTimes ( 1 ) ;
461
+ expect ( uploadSpy ) . toHaveBeenCalledTimes ( 1 ) ;
462
+ } ) ;
391
463
} ) ;
392
464
393
465
async function runPushTestWithError ( localBundleDir : string , overwrite : boolean , errorText : string , parmsIn ?: IHandlerParameters ) {
@@ -411,8 +483,14 @@ async function runPushTestWithError(localBundleDir: string, overwrite: boolean,
411
483
expect ( err . message ) . toContain ( errorText ) ;
412
484
}
413
485
414
- async function runPushTest ( localBundleDir : string , overwrite : boolean , expectedResponse : string ) {
415
- const parms = getCommonParmsForPushTests ( ) ;
486
+ async function runPushTest ( localBundleDir : string , overwrite : boolean , expectedResponse : string , parmsIn ?: IHandlerParameters ) {
487
+ let parms : IHandlerParameters ;
488
+ if ( parmsIn === undefined ) {
489
+ parms = getCommonParmsForPushTests ( ) ;
490
+ }
491
+ else {
492
+ parms = parmsIn ;
493
+ }
416
494
parms . arguments . overwrite = overwrite ;
417
495
418
496
let err : Error ;
0 commit comments