@@ -4,21 +4,25 @@ const watch = jest.fn().mockReturnValue({ close });
44
55jest . setMock ( 'webpack' , ( ) => ( { run, watch } ) ) ; // try to get rid of this.
66jest . mock ( '../watchModeIPC' ) ;
7+ jest . mock ( 'webpack/lib/Stats' ) ;
78
89let webpackWorker ;
910let promiseMock ;
1011let webpackMock ;
12+ let webpackStatsMock ;
1113let notifyIPCWatchCompileDone ;
1214
1315describe ( 'webpackWorker' , ( ) => {
1416 beforeEach ( ( ) => {
1517 promiseMock = require ( 'bluebird' ) ;
1618 webpackMock = require ( 'webpack' ) ;
19+ webpackStatsMock = require ( 'webpack/lib/Stats' ) ;
1720 webpackWorker = require ( '../webpackWorker.js' ) ;
1821 notifyIPCWatchCompileDone = require ( '../watchModeIPC' ) . notifyIPCWatchCompileDone ;
1922 jest . doMock ( 'testConfig' , ( ) => ( { webpack : 'config' } ) , { virtual : true } ) ;
2023 jest . resetModules ( ) ;
2124 jest . clearAllMocks ( ) ;
25+ process . removeAllListeners ( ) ;
2226 } ) ;
2327
2428 describe ( 'arguments' , ( ) => {
@@ -268,6 +272,28 @@ describe('webpackWorker', () => {
268272 finishedCallback ( null , statsObj ) ;
269273 expect ( statsObj . toString . mock . calls ) . toMatchSnapshot ( ) ;
270274 } ) ;
275+
276+ it ( 'should translate stats string to object' , ( ) => {
277+ jest . spyOn ( console , 'log' ) ;
278+ let presetToOptions = jest . spyOn ( webpackStatsMock , 'presetToOptions' ) ;
279+
280+ const doneCallback = jest . fn ( ) ;
281+
282+ webpackWorker ( 'testConfig' , {
283+ stats : true ,
284+ modulesSort : 'name' ,
285+ chunksSort : 'size' ,
286+ assetsSort : 'name' ,
287+ exclude : [ 'file' ] ,
288+ colors : true
289+ } , 0 , 1 , doneCallback ) ;
290+
291+ expect ( promiseMock . resolve . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { webpack : 'config' } ) ;
292+ const thenCb = promiseMock . then . mock . calls [ 0 ] [ 0 ] ;
293+ thenCb ( { webpack : 'config' , name : 'testApp' , 'stats' : 'verbose' } ) ;
294+
295+ expect ( presetToOptions ) . toHaveBeenCalled ( ) ;
296+ } )
271297 } ) ;
272298 } ) ;
273299
0 commit comments