File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,17 @@ describe('ServerlessWebpack', () => {
200200 return null ;
201201 } ) ;
202202 } ) ;
203+
204+ it ( 'should skip compile if requested' , ( ) => {
205+ slsw . options . build = false ;
206+ return expect ( slsw . hooks [ 'before:invoke:local:invoke' ] ( ) ) . to . be . fulfilled
207+ . then ( ( ) => {
208+ expect ( slsw . serverless . pluginManager . spawn ) . to . have . been . calledOnce ;
209+ expect ( slsw . serverless . pluginManager . spawn ) . to . have . been . calledWithExactly ( 'webpack:validate' ) ;
210+ expect ( slsw . prepareLocalInvoke ) . to . have . been . calledOnce ;
211+ return null ;
212+ } ) ;
213+ } ) ;
203214 }
204215 } ,
205216 {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ module.exports.create = sandbox => {
88 const fsExtraMock = {
99 copy : sandbox . stub ( ) . yields ( ) ,
1010 pathExists : sandbox . stub ( ) . yields ( ) ,
11+ pathExistsSync : sandbox . stub ( ) . returns ( false ) ,
1112 removeSync : sandbox . stub ( )
1213 } ;
1314
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ describe('validate', () => {
5353
5454 afterEach ( ( ) => {
5555 fsExtraMock . removeSync . reset ( ) ;
56+ fsExtraMock . pathExistsSync . reset ( ) ;
5657 sandbox . restore ( ) ;
5758 } ) ;
5859
@@ -733,6 +734,38 @@ describe('validate', () => {
733734 } ) ;
734735 } ) ;
735736 } ) ;
737+ } ) ;
736738
739+ describe ( 'with skipped builds' , ( ) => {
740+ it ( 'should keep output directory' , ( ) => {
741+ const testConfig = {
742+ entry : 'test' ,
743+ output : { } ,
744+ } ;
745+ const testServicePath = 'testpath' ;
746+ module . serverless . config . servicePath = testServicePath ;
747+ _ . set ( module . serverless . service , 'custom.webpack.config' , testConfig ) ;
748+ module . skipCompile = true ;
749+ fsExtraMock . pathExistsSync . returns ( true ) ;
750+ return module
751+ . validate ( )
752+ . then ( ( ) => {
753+ expect ( module . keepOutputDirectory ) . to . be . true ;
754+ return null ;
755+ } ) ;
756+ } ) ;
757+
758+ it ( 'should fail without exiting output' , ( ) => {
759+ const testConfig = {
760+ entry : 'test' ,
761+ output : { } ,
762+ } ;
763+ const testServicePath = 'testpath' ;
764+ module . serverless . config . servicePath = testServicePath ;
765+ _ . set ( module . serverless . service , 'custom.webpack.config' , testConfig ) ;
766+ module . skipCompile = true ;
767+ fsExtraMock . pathExistsSync . returns ( false ) ;
768+ return expect ( module . validate ( ) ) . to . be . rejectedWith ( / N o c o m p i l e d o u t p u t f o u n d / ) ;
769+ } ) ;
737770 } ) ;
738771} ) ;
You can’t perform that action at this time.
0 commit comments