@@ -5,7 +5,7 @@ const { run, runAndGetWatchProc, isWebpack5 } = require('../../utils/test-utils'
5
5
const { writeFileSync } = require ( 'fs' ) ;
6
6
const { resolve } = require ( 'path' ) ;
7
7
8
- const wordsInStatsv4 = [ 'Hash' , 'Version' , 'Time' , ' Built at:', 'main.js' ] ;
8
+ const wordsInStatsv4 = [ 'Hash' , 'Built at:' , 'main.js' ] ;
9
9
const wordsInStatsv5 = [ 'asset' , 'index.js' , 'compiled successfully' ] ;
10
10
11
11
describe ( 'basic' , ( ) => {
@@ -118,11 +118,10 @@ describe('basic', () => {
118
118
} ) ;
119
119
} ) ;
120
120
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 ) ;
123
123
124
124
let modified = false ;
125
- let hasWarning = false ;
126
125
127
126
proc . stdout . on ( 'data' , ( chunk ) => {
128
127
const data = stripAnsi ( chunk . toString ( ) ) ;
@@ -138,7 +137,7 @@ describe('basic', () => {
138
137
}
139
138
}
140
139
141
- if ( ! modified && ! hasWarning ) {
140
+ if ( ! modified ) {
142
141
process . nextTick ( ( ) => {
143
142
writeFileSync ( resolve ( __dirname , './src/index.js' ) , `console.log('watch flag test');` ) ;
144
143
} ) ;
@@ -154,51 +153,27 @@ describe('basic', () => {
154
153
proc . stderr . on ( 'data' , ( chunk ) => {
155
154
const data = stripAnsi ( chunk . toString ( ) ) ;
156
155
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
+ ) ;
160
159
} ) ;
161
160
} ) ;
162
161
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' ] ) ;
187
164
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
+ } ) ;
198
170
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' ] ) ;
200
173
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 ( ) ;
203
178
} ) ;
204
179
} ) ;
0 commit comments