@@ -5,7 +5,7 @@ const { run, runAndGetWatchProc, isWebpack5 } = require('../../utils/test-utils'
55const { writeFileSync } = require ( 'fs' ) ;
66const { resolve } = require ( 'path' ) ;
77
8- const wordsInStatsv4 = [ 'Hash' , 'Version' , 'Time' , ' Built at:', 'main.js' ] ;
8+ const wordsInStatsv4 = [ 'Hash' , 'Built at:' , 'main.js' ] ;
99const wordsInStatsv5 = [ 'asset' , 'index.js' , 'compiled successfully' ] ;
1010
1111describe ( 'basic' , ( ) => {
@@ -118,11 +118,10 @@ describe('basic', () => {
118118 } ) ;
119119 } ) ;
120120
121- it ( 'should recompile upon file change using the `command ` option and the `-- watch` option and log warning ' , ( done ) => {
122- const proc = runAndGetWatchProc ( __dirname , [ 'watch' , '--watch ' , '--mode ' , 'development ' ] , false , '' , true ) ;
121+ it ( 'should log warning about the `watch ` option in the configuration and recompile upon file change using the `watch` command ' , ( done ) => {
122+ const proc = runAndGetWatchProc ( __dirname , [ '-- watch' , '--mode ' , 'development' , '--config ', './watch.config.js ' ] , false , '' , true ) ;
123123
124124 let modified = false ;
125- let hasWarning = false ;
126125
127126 proc . stdout . on ( 'data' , ( chunk ) => {
128127 const data = stripAnsi ( chunk . toString ( ) ) ;
@@ -138,7 +137,7 @@ describe('basic', () => {
138137 }
139138 }
140139
141- if ( ! modified && ! hasWarning ) {
140+ if ( ! modified ) {
142141 process . nextTick ( ( ) => {
143142 writeFileSync ( resolve ( __dirname , './src/index.js' ) , `console.log('watch flag test');` ) ;
144143 } ) ;
@@ -154,51 +153,27 @@ describe('basic', () => {
154153 proc . stderr . on ( 'data' , ( chunk ) => {
155154 const data = stripAnsi ( chunk . toString ( ) ) ;
156155
157- hasWarning = true ;
158-
159- expect ( data ) . toContain ( "No need to use the '--watch, -w' option together with the 'watch' command, it does not make sense" ) ;
156+ expect ( data ) . toContain (
157+ "No need to use the 'watch' command together with '{ watch: true }' configuration, it does not make sense." ,
158+ ) ;
160159 } ) ;
161160 } ) ;
162161
163- it ( 'should recompile upon file change using the `command` option and the `--no-watch` option and log warning' , ( done ) => {
164- const proc = runAndGetWatchProc ( __dirname , [ 'watch' , '--no-watch' , '--mode' , 'development' ] , false , '' , true ) ;
165-
166- let modified = false ;
167- let hasWarning = false ;
168-
169- proc . stdout . on ( 'data' , ( chunk ) => {
170- const data = stripAnsi ( chunk . toString ( ) ) ;
171-
172- if ( data . includes ( 'index.js' ) ) {
173- if ( isWebpack5 ) {
174- for ( const word of wordsInStatsv5 ) {
175- expect ( data ) . toContain ( word ) ;
176- }
177- } else {
178- for ( const word of wordsInStatsv4 ) {
179- expect ( data ) . toContain ( word ) ;
180- }
181- }
182-
183- if ( ! modified && ! hasWarning ) {
184- process . nextTick ( ( ) => {
185- writeFileSync ( resolve ( __dirname , './src/index.js' ) , `console.log('watch flag test');` ) ;
186- } ) ;
162+ it ( 'should recompile upon file change using the `command` option and the `--watch` option and log warning' , async ( ) => {
163+ const { exitCode, stderr, stdout } = await run ( __dirname , [ 'watch' , '--watch' , '--mode' , 'development' ] ) ;
187164
188- modified = true ;
189- } else {
190- proc . kill ( ) ;
191- done ( ) ;
192- }
193- }
194- } ) ;
195-
196- proc . stderr . on ( 'data' , ( chunk ) => {
197- const data = stripAnsi ( chunk . toString ( ) ) ;
165+ expect ( exitCode ) . toBe ( 2 ) ;
166+ expect ( stderr ) . toContain ( "Error: Unknown option '--watch'" ) ;
167+ expect ( stderr ) . toContain ( "Run 'webpack --help' to see available commands and options" ) ;
168+ expect ( stdout ) . toBeFalsy ( ) ;
169+ } ) ;
198170
199- hasWarning = true ;
171+ it ( 'should recompile upon file change using the `command` option and the `--no-watch` option and log warning' , async ( ) => {
172+ const { exitCode, stderr, stdout } = await run ( __dirname , [ 'watch' , '--no-watch' , '--mode' , 'development' ] ) ;
200173
201- expect ( data ) . toContain ( "No need to use the '--no-watch' option together with the 'watch' command, it does not make sense" ) ;
202- } ) ;
174+ expect ( exitCode ) . toBe ( 2 ) ;
175+ expect ( stderr ) . toContain ( "Error: Unknown option '--no-watch'" ) ;
176+ expect ( stderr ) . toContain ( "Run 'webpack --help' to see available commands and options" ) ;
177+ expect ( stdout ) . toBeFalsy ( ) ;
203178 } ) ;
204179} ) ;
0 commit comments