11'use strict' ;
22
3- const { runAndGetWatchProc } = require ( '../utils/test-utils' ) ;
3+ const { runAndGetWatchProc, isWebpack5 , isWindows } = require ( '../utils/test-utils' ) ;
44const { writeFileSync } = require ( 'fs' ) ;
55const { resolve } = require ( 'path' ) ;
6- const { version } = require ( 'webpack' ) ;
76
87const wordsInStatsv4 = [ 'Hash' , 'Version' , 'Time' , 'Built at:' , 'main.js' ] ;
98const wordsInStatsv5 = [ 'asset' , 'index.js' , 'compiled successfully' ] ;
@@ -14,13 +13,13 @@ describe('--watch flag', () => {
1413 let semaphore = 1 ;
1514 proc . stdout . on ( 'data' , ( chunk ) => {
1615 const data = chunk . toString ( ) ;
17- if ( semaphore === 1 && data . includes ( 'watching files for updates' ) ) {
16+ if ( data . includes ( 'watching files for updates' ) ) {
1817 writeFileSync ( resolve ( __dirname , './src/index.js' ) , `console.log('watch flag test');` ) ;
19- semaphore -- ;
18+ semaphore = 0 ;
2019 return ;
2120 }
22- if ( semaphore === 0 ) {
23- if ( version . startsWith ( '5' ) ) {
21+ if ( semaphore === 0 && data . includes ( 'index.js' ) ) {
22+ if ( isWebpack5 ) {
2423 for ( const word of wordsInStatsv5 ) {
2524 expect ( data ) . toContain ( word ) ;
2625 }
@@ -36,4 +35,30 @@ describe('--watch flag', () => {
3635 }
3736 } ) ;
3837 } ) ;
38+
39+ it ( 'should print compilation lifecycle' , ( done ) => {
40+ const proc = runAndGetWatchProc ( __dirname , [ '--watch' ] , false , '' , true ) ;
41+ let semaphore = 0 ;
42+ proc . stdout . on ( 'data' , ( chunk ) => {
43+ const data = chunk . toString ( ) ;
44+ if ( data . includes ( 'Compilation starting' ) || data . includes ( 'Compilation finished' ) ) {
45+ semaphore ++ ;
46+ }
47+ // TODO Fix on windows
48+ if ( ( isWindows || semaphore === 2 ) && data . includes ( 'index.js' ) ) {
49+ if ( isWebpack5 ) {
50+ for ( const word of wordsInStatsv5 ) {
51+ expect ( data ) . toContain ( word ) ;
52+ }
53+ } else {
54+ for ( const word of wordsInStatsv4 ) {
55+ expect ( data ) . toContain ( word ) ;
56+ }
57+ }
58+ proc . kill ( ) ;
59+ done ( ) ;
60+ return ;
61+ }
62+ } ) ;
63+ } ) ;
3964} ) ;
0 commit comments