@@ -338,6 +338,152 @@ describe("Bundle01", () => {
338
338
expect ( err ) . toBeDefined ( ) ;
339
339
expect ( err . message ) . toMatchSnapshot ( ) ;
340
340
} ) ;
341
+ it ( "should tolerate absence of .nodejsapp directory" , ( ) => {
342
+
343
+ // Create a Bundle
344
+ const bund = new Bundle ( "__tests__/__resources__/ExampleBundle03" , false , false ) ;
345
+
346
+ // Mocks for the manifest
347
+ const spy1 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
348
+ const spy2 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
349
+ const spy3 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
350
+ // Mocks for the Nodejsapp - startscript exists
351
+ const spy4 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
352
+ // Mocks for the Nodejsapp - dir exists
353
+ const spy5 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
354
+
355
+ bund . addNodejsappDefinition ( "NodeName" , "__tests__/__resources__/ExampleBundle03/Artefact1" , 1000 ) ;
356
+ bund . prepareForSave ( ) ;
357
+
358
+ // Check the output as JSON
359
+ expect ( JSON . stringify ( bund . getManifest ( ) ) ) . toMatchSnapshot ( ) ;
360
+ } ) ;
361
+ it ( "should detect unwritable .nodejsapp directory" , ( ) => {
362
+
363
+ // Create a Bundle
364
+ const bund = new Bundle ( "__tests__/__resources__/ExampleBundle03" , false , false ) ;
365
+
366
+ // Mocks for the manifest
367
+ const spy1 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
368
+ const spy2 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
369
+ const spy3 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
370
+ // Mocks for the Nodejsapp - startscript exists
371
+ const spy4 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
372
+ // Mocks for the Nodejsapp - dir exists
373
+ const spy5 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
374
+ // Mocks for the Nodejsapp - dir not writable
375
+ const spy6 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => { throw new Error ( "Wibble" ) ; } ) ;
376
+
377
+ bund . addNodejsappDefinition ( "NodeName" , "__tests__/__resources__/ExampleBundle03/Artefact1" , 1000 ) ;
378
+ let err : Error ;
379
+ try {
380
+ bund . prepareForSave ( ) ;
381
+ }
382
+ catch ( error ) {
383
+ err = error ;
384
+ }
385
+
386
+ expect ( err ) . toBeDefined ( ) ;
387
+ expect ( err . message ) . toMatchSnapshot ( ) ;
388
+ } ) ;
389
+ it ( "should complain if existing .nodejsapp file isn't overwritable" , ( ) => {
390
+
391
+ // Create a Bundle
392
+ const bund = new Bundle ( "__tests__/__resources__/ExampleBundle03" , false , false ) ;
393
+
394
+ // Mocks for the manifest
395
+ const spy1 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
396
+ const spy2 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
397
+ const spy3 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
398
+ // Mocks for the Nodejsapp - startscript exists
399
+ const spy4 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
400
+ // Mocks for the Nodejsapp - dir exists
401
+ const spy5 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
402
+ // Mocks for the Nodejsapp - dir writable
403
+ const spy6 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
404
+ // Mocks for the Nodejsapp - .nodejsapp exists
405
+ const spy7 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
406
+
407
+ bund . addNodejsappDefinition ( "NodeName" , "__tests__/__resources__/ExampleBundle03/Artefact1" , 1000 ) ;
408
+ let err : Error ;
409
+ try {
410
+ bund . prepareForSave ( ) ;
411
+ }
412
+ catch ( error ) {
413
+ err = error ;
414
+ }
415
+
416
+ expect ( err ) . toBeDefined ( ) ;
417
+ expect ( err . message ) . toMatchSnapshot ( ) ;
418
+ } ) ;
419
+ it ( "should complain if no write permission to existing .nodejsapp" , ( ) => {
420
+
421
+ // Create a Bundle
422
+ const bund = new Bundle ( "__tests__/__resources__/ExampleBundle03" , false , true ) ;
423
+
424
+ // Mocks for the manifest
425
+ const spy1 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
426
+ const spy2 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
427
+ const spy3 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
428
+ // Mocks for the Nodejsapp - startscript exists
429
+ const spy4 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
430
+ // Mocks for the Nodejsapp - dir exists
431
+ const spy5 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
432
+ // Mocks for the Nodejsapp - dir writable
433
+ const spy6 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
434
+ // Mocks for the Nodejsapp - .nodejsapp exists
435
+ const spy7 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
436
+ // Mocks for the Nodejsapp - .nodejsapp not writable
437
+ const spy8 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => { throw new Error ( "Wibble" ) ; } ) ;
438
+
439
+ bund . addNodejsappDefinition ( "NodeName" , "__tests__/__resources__/ExampleBundle03/Artefact1" , 1000 ) ;
440
+ let err : Error ;
441
+ try {
442
+ bund . prepareForSave ( ) ;
443
+ }
444
+ catch ( error ) {
445
+ err = error ;
446
+ }
447
+
448
+ expect ( err ) . toBeDefined ( ) ;
449
+ expect ( err . message ) . toMatchSnapshot ( ) ;
450
+ } ) ;
451
+ it ( "should complain if no write permission to existing .profile" , ( ) => {
452
+
453
+ // Create a Bundle
454
+ const bund = new Bundle ( "__tests__/__resources__/ExampleBundle03" , false , true ) ;
455
+
456
+ // Mocks for the manifest
457
+ const spy1 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
458
+ const spy2 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
459
+ const spy3 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( false ) ) ;
460
+ // Mocks for the Nodejsapp - startscript exists
461
+ const spy4 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
462
+ // Mocks for the Nodejsapp - dir exists
463
+ const spy5 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
464
+ // Mocks for the Nodejsapp - dir writable
465
+ const spy6 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
466
+ // Mocks for the Nodejsapp - .nodejsapp exists
467
+ const spy7 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
468
+ // Mocks for the Nodejsapp - .nodejsapp writable
469
+ const spy8 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
470
+ // Mocks for the Nodejsapp - .profile exists
471
+ const spy9 = jest . spyOn ( fs , "existsSync" ) . mockImplementationOnce ( ( ) => ( true ) ) ;
472
+ // Mocks for the Nodejsapp - .profile writable
473
+ const spy10 = jest . spyOn ( fs , "accessSync" ) . mockImplementationOnce ( ( ) => { throw new Error ( "Wibble" ) ; } ) ;
474
+
475
+ bund . addNodejsappDefinition ( "NodeName" , "__tests__/__resources__/ExampleBundle03/Artefact1" , 1000 ) ;
476
+ let err : Error ;
477
+ try {
478
+ bund . prepareForSave ( ) ;
479
+ }
480
+ catch ( error ) {
481
+ err = error ;
482
+ }
483
+
484
+ expect ( err ) . toBeDefined ( ) ;
485
+ expect ( err . message ) . toMatchSnapshot ( ) ;
486
+ } ) ;
341
487
it ( "should complain if exceptions are thrown during manifest parsing" , ( ) => {
342
488
343
489
const spy1 = jest . spyOn ( JSON , "parse" ) . mockImplementationOnce ( ( ) => { throw new Error ( "Wibble" ) ; } ) ;
0 commit comments