@@ -458,6 +458,59 @@ describe('packExternalModules', () => {
458
458
] ) ) ;
459
459
} ) ;
460
460
461
+ it ( 'should exclude external modules when forced' , ( ) => {
462
+ const expectedCompositePackageJSON = {
463
+ name : 'test-service' ,
464
+ version : '1.0.0' ,
465
+ description : 'Packaged externals for test-service' ,
466
+ private : true ,
467
+ dependencies : {
468
+ '@scoped/vendor' : '1.0.0' ,
469
+ bluebird : '^3.4.0' ,
470
+ pg : '^4.3.5'
471
+ }
472
+ } ;
473
+ const expectedPackageJSON = {
474
+ dependencies : {
475
+ '@scoped/vendor' : '1.0.0' ,
476
+ bluebird : '^3.4.0' ,
477
+ pg : '^4.3.5'
478
+ }
479
+ } ;
480
+ serverless . service . custom = {
481
+ webpackIncludeModules : {
482
+ forceInclude : [ 'pg' ] ,
483
+ forceExclude : [ 'uuid' ]
484
+ }
485
+ } ;
486
+ module . webpackOutputPath = 'outputPath' ;
487
+ fsExtraMock . pathExists . yields ( null , false ) ;
488
+ fsExtraMock . copy . yields ( ) ;
489
+ childProcessMock . exec . onFirstCall ( ) . yields ( null , '{}' , '' ) ;
490
+ childProcessMock . exec . onSecondCall ( ) . yields ( null , '' , '' ) ;
491
+ childProcessMock . exec . onThirdCall ( ) . yields ( ) ;
492
+ return expect ( module . packExternalModules ( stats ) ) . to . be . fulfilled
493
+ . then ( ( ) => BbPromise . all ( [
494
+ // The module package JSON and the composite one should have been stored
495
+ expect ( writeFileSyncStub ) . to . have . been . calledTwice ,
496
+ expect ( writeFileSyncStub . firstCall . args [ 1 ] ) . to . equal ( JSON . stringify ( expectedCompositePackageJSON , null , 2 ) ) ,
497
+ expect ( writeFileSyncStub . secondCall . args [ 1 ] ) . to . equal ( JSON . stringify ( expectedPackageJSON , null , 2 ) ) ,
498
+ // The modules should have been copied
499
+ expect ( fsExtraMock . copy ) . to . have . been . calledOnce ,
500
+ // npm ls and npm prune should have been called
501
+ expect ( childProcessMock . exec ) . to . have . been . calledThrice ,
502
+ expect ( childProcessMock . exec . firstCall ) . to . have . been . calledWith (
503
+ 'npm ls -prod -json -depth=1'
504
+ ) ,
505
+ expect ( childProcessMock . exec . secondCall ) . to . have . been . calledWith (
506
+ 'npm install'
507
+ ) ,
508
+ expect ( childProcessMock . exec . thirdCall ) . to . have . been . calledWith (
509
+ 'npm prune'
510
+ )
511
+ ] ) ) ;
512
+ } ) ;
513
+
461
514
it ( 'should read package-lock if found' , ( ) => {
462
515
const expectedCompositePackageJSON = {
463
516
name : 'test-service' ,
0 commit comments