1
1
'use strict' ;
2
2
3
- const { join , resolve } = require ( 'path' ) ;
3
+ const path = require ( 'path' ) ;
4
4
const execa = require ( 'execa' ) ;
5
5
const internalIp = require ( 'internal-ip' ) ;
6
6
const testBin = require ( '../helpers/test-bin' ) ;
@@ -9,11 +9,9 @@ const isWebpack5 = require('../helpers/isWebpack5');
9
9
// skip if webpack-dev-server is not linked
10
10
let runCLITest = describe ;
11
11
let basePath ;
12
+
12
13
try {
13
- basePath = join ( require . resolve ( 'webpack-dev-server' ) , '..' , '..' ) . replace (
14
- / \\ / g,
15
- '/'
16
- ) ;
14
+ basePath = path . join ( require . resolve ( 'webpack-dev-server' ) , '..' , '..' ) ;
17
15
} catch {
18
16
runCLITest = describe . skip ;
19
17
}
@@ -39,7 +37,9 @@ runCLITest('CLI', () => {
39
37
'$1 Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT'
40
38
)
41
39
. replace ( / w e b p a c k [ ^ ) ] + / g, 'webpack x.x.x' )
40
+ . replace ( new RegExp ( quotemeta ( basePath . replace ( / \\ / g, '/' ) ) , 'g' ) , 'Xdir' )
42
41
. replace ( new RegExp ( quotemeta ( basePath ) , 'g' ) , 'Xdir' )
42
+ . replace ( / [ \\ / ] s t a t i c / , '/static' )
43
43
. replace ( / ( H a s h : ) [ a - z 0 - 9 ] + / g, '$1 X' )
44
44
. replace ( / d e p e n d e n c i e s : X m s / g, '' )
45
45
. replace ( / , a d d i t i o n a l r e s o l v i n g : X m s / g, '' ) ;
@@ -178,7 +178,7 @@ runCLITest('CLI', () => {
178
178
it ( 'should log public path' , ( done ) => {
179
179
testBin (
180
180
false ,
181
- resolve ( __dirname , '../fixtures/dev-public-path/webpack.config.js' )
181
+ path . resolve ( __dirname , '../fixtures/dev-public-path/webpack.config.js' )
182
182
)
183
183
. then ( ( output ) => {
184
184
expect ( output . exitCode ) . toEqual ( 0 ) ;
@@ -194,10 +194,35 @@ runCLITest('CLI', () => {
194
194
} ) ;
195
195
} ) ;
196
196
197
+ it ( 'should log static' , ( done ) => {
198
+ testBin (
199
+ false ,
200
+ path . resolve ( __dirname , '../fixtures/static/webpack.config.js' )
201
+ )
202
+ . then ( ( output ) => {
203
+ console . log ( output ) ;
204
+ expect ( output . exitCode ) . toEqual ( 0 ) ;
205
+ done ( ) ;
206
+ } )
207
+ . catch ( ( err ) => {
208
+ const staticDirectory = path . resolve (
209
+ __dirname ,
210
+ '../fixtures/static/static'
211
+ ) ;
212
+
213
+ // for windows
214
+ expect ( err . stderr ) . toContain (
215
+ `Content not from webpack is served from '${ staticDirectory } ' directory`
216
+ ) ;
217
+ expect ( err . stderr ) . toContain ( 'Compiled successfully.' ) ;
218
+ done ( ) ;
219
+ } ) ;
220
+ } ) ;
221
+
197
222
it ( 'should accept the promise function of webpack.config.js' , ( done ) => {
198
223
testBin (
199
224
false ,
200
- resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
225
+ path . resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
201
226
)
202
227
. then ( ( output ) => {
203
228
expect ( output . exitCode ) . toEqual ( 0 ) ;
@@ -211,8 +236,8 @@ runCLITest('CLI', () => {
211
236
} ) ;
212
237
213
238
it ( 'should exit the process when SIGINT is detected' , ( done ) => {
214
- const cliPath = resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
215
- const examplePath = resolve ( __dirname , '../../examples/cli/public' ) ;
239
+ const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
240
+ const examplePath = path . resolve ( __dirname , '../../examples/cli/public' ) ;
216
241
const cp = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
217
242
218
243
cp . stderr . on ( 'data' , ( data ) => {
@@ -231,8 +256,8 @@ runCLITest('CLI', () => {
231
256
} ) ;
232
257
233
258
it ( 'should exit the process when SIGINT is detected, even before the compilation is done' , ( done ) => {
234
- const cliPath = resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
235
- const cwd = resolve ( __dirname , '../fixtures/cli' ) ;
259
+ const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
260
+ const cwd = path . resolve ( __dirname , '../fixtures/cli' ) ;
236
261
const cp = execa ( 'node' , [ cliPath ] , { cwd } ) ;
237
262
238
263
let killed = false ;
@@ -253,8 +278,8 @@ runCLITest('CLI', () => {
253
278
} ) ;
254
279
255
280
it ( 'should exit the process when stdin ends if --stdin' , ( done ) => {
256
- const cliPath = resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
257
- const examplePath = resolve ( __dirname , '../../examples/cli/public' ) ;
281
+ const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
282
+ const examplePath = path . resolve ( __dirname , '../../examples/cli/public' ) ;
258
283
const cp = execa ( 'node' , [ cliPath , '--stdin' ] , { cwd : examplePath } ) ;
259
284
260
285
cp . stderr . on ( 'data' , ( data ) => {
@@ -274,8 +299,8 @@ runCLITest('CLI', () => {
274
299
} ) ;
275
300
276
301
it ( 'should exit the process when stdin ends if --stdin, even before the compilation is done' , ( done ) => {
277
- const cliPath = resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
278
- const cwd = resolve ( __dirname , '../fixtures/cli' ) ;
302
+ const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
303
+ const cwd = path . resolve ( __dirname , '../fixtures/cli' ) ;
279
304
const cp = execa ( 'node' , [ cliPath , '--stdin' ] , { cwd } ) ;
280
305
281
306
let killed = false ;
@@ -299,8 +324,8 @@ runCLITest('CLI', () => {
299
324
// TODO: do not skip after @webpack -cli/serve passes null port by default
300
325
// https://github.com/webpack/webpack-cli/pull/2126
301
326
it . skip ( 'should use different random port when multiple instances are started on different processes' , ( done ) => {
302
- const cliPath = resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
303
- const cwd = resolve ( __dirname , '../fixtures/cli' ) ;
327
+ const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
328
+ const cwd = path . resolve ( __dirname , '../fixtures/cli' ) ;
304
329
305
330
const cp = execa ( 'node' , [ cliPath , '--colors=false' ] , { cwd } ) ;
306
331
const cp2 = execa ( 'node' , [ cliPath , '--colors=false' ] , { cwd } ) ;
0 commit comments