11'use strict' ;
22
33const _ = require ( 'lodash' ) ;
4+ const BbPromise = require ( 'bluebird' ) ;
45const chai = require ( 'chai' ) ;
56const sinon = require ( 'sinon' ) ;
67const mockery = require ( 'mockery' ) ;
@@ -232,14 +233,15 @@ describe('validate', () => {
232233 entry : 'testentry' ,
233234 } ;
234235 mockery . registerMock ( requiredPath , loadedConfig ) ;
235- return module
236- . validate ( )
237- . then ( ( ) => {
238- expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
239- expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
240- mockery . deregisterMock ( requiredPath ) ;
241- return null ;
242- } ) ;
236+ return expect ( module . validate ( ) ) . to . fulfilled
237+ . then ( ( ) => {
238+ expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
239+ expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
240+ return null ;
241+ } )
242+ . finally ( ( ) => {
243+ mockery . deregisterMock ( requiredPath ) ;
244+ } ) ;
243245 } ) ;
244246
245247 it ( 'should load a async webpack config from file if `custom.webpack` is a string' , ( ) => {
@@ -252,16 +254,17 @@ describe('validate', () => {
252254 const loadedConfig = {
253255 entry : 'testentry' ,
254256 } ;
255- const loadedConfigPromise = Promise . resolve ( loadedConfig ) ;
257+ const loadedConfigPromise = BbPromise . resolve ( loadedConfig ) ;
256258 mockery . registerMock ( requiredPath , loadedConfigPromise ) ;
257- return module
258- . validate ( )
259- . then ( ( ) => {
260- expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
261- expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
262- mockery . deregisterMock ( requiredPath ) ;
263- return null ;
264- } ) ;
259+ return expect ( module . validate ( ) ) . to . be . fulfilled
260+ . then ( ( ) => {
261+ expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
262+ expect ( module . webpackConfig ) . to . deep . equal ( loadedConfig ) ;
263+ return null ;
264+ } )
265+ . finally ( ( ) => {
266+ mockery . deregisterMock ( requiredPath ) ;
267+ } ) ;
265268 } ) ;
266269
267270 it ( 'should catch errors while loading a async webpack config from file if `custom.webpack` is a string' , ( ) => {
@@ -271,16 +274,16 @@ describe('validate', () => {
271274 module . serverless . config . servicePath = testServicePath ;
272275 module . serverless . service . custom . webpack = testConfig ;
273276 serverless . utils . fileExistsSync = sinon . stub ( ) . returns ( true ) ;
274- const loadedConfigPromise = Promise . reject ( 'config failed to load' ) ;
277+ const loadedConfigPromise = BbPromise . reject ( 'config failed to load' ) ;
275278 mockery . registerMock ( requiredPath , loadedConfigPromise ) ;
276- return module
277- . validate ( )
278- . catch ( e => {
279- expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
280- expect ( e ) . to . eql ( 'config failed to load' ) ;
281- mockery . deregisterMock ( requiredPath ) ;
282- return null ;
283- } ) ;
279+ return expect ( module . validate ( ) ) . to . be . rejectedWith ( 'config failed to load' )
280+ . then ( ( ) => {
281+ expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
282+ return null ;
283+ } )
284+ . finally ( ( ) => {
285+ mockery . deregisterMock ( requiredPath ) ;
286+ } ) ;
284287 } ) ;
285288
286289 it ( 'should load a wrong thenable webpack config as normal object from file if `custom.webpack` is a string' , ( ) => {
@@ -295,14 +298,15 @@ describe('validate', () => {
295298 entry : 'testentry' ,
296299 } ;
297300 mockery . registerMock ( requiredPath , loadedConfig ) ;
298- return module
299- . validate ( )
300- . then ( ( ) => {
301- expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
302- expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
303- mockery . deregisterMock ( requiredPath ) ;
304- return null ;
305- } ) ;
301+ return expect ( module . validate ( ) ) . to . be . fulfilled
302+ . then ( ( ) => {
303+ expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
304+ expect ( module . webpackConfig ) . to . deep . equal ( loadedConfig ) ;
305+ return null ;
306+ } )
307+ . finally ( ( ) => {
308+ mockery . deregisterMock ( requiredPath ) ;
309+ } ) ;
306310 } ) ;
307311
308312 it ( 'should throw if providing an invalid file' , ( ) => {
@@ -311,7 +315,7 @@ describe('validate', () => {
311315 module . serverless . config . servicePath = testServicePath ;
312316 module . serverless . service . custom . webpack = testConfig ;
313317 serverless . utils . fileExistsSync = sinon . stub ( ) . returns ( false ) ;
314- expect ( module . validate . bind ( module ) ) . to . throw ( / c o u l d n o t f i n d / ) ;
318+ return expect ( module . validate ( ) ) . to . be . rejectedWith ( / c o u l d n o t f i n d / ) ;
315319 } ) ;
316320
317321 it ( 'should load a default file if no custom config is provided' , ( ) => {
@@ -324,14 +328,15 @@ describe('validate', () => {
324328 entry : 'testentry' ,
325329 } ;
326330 mockery . registerMock ( requiredPath , loadedConfig ) ;
327- return module
328- . validate ( )
329- . then ( ( ) => {
330- expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
331- expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
332- mockery . deregisterMock ( requiredPath ) ;
333- return null ;
334- } ) ;
331+ return expect ( module . validate ( ) ) . to . be . fulfilled
332+ . then ( ( ) => {
333+ expect ( serverless . utils . fileExistsSync ) . to . have . been . calledWith ( requiredPath ) ;
334+ expect ( module . webpackConfig ) . to . eql ( loadedConfig ) ;
335+ return null ;
336+ } )
337+ . finally ( ( ) => {
338+ mockery . deregisterMock ( requiredPath ) ;
339+ } ) ;
335340 } ) ;
336341
337342 it ( 'should fail when importing a broken configuration file' , ( ) => {
0 commit comments