11'use strict' ;
22
3- const { join , resolve } = require ( 'path' ) ;
3+ const path = require ( 'path' ) ;
44const execa = require ( 'execa' ) ;
55const internalIp = require ( 'internal-ip' ) ;
66const testBin = require ( '../helpers/test-bin' ) ;
@@ -9,11 +9,9 @@ const isWebpack5 = require('../helpers/isWebpack5');
99// skip if webpack-dev-server is not linked
1010let runCLITest = describe ;
1111let basePath ;
12+
1213try {
13- basePath = join ( require . resolve ( 'webpack-dev-server' ) , '..' , '..' ) . replace (
14- / \\ / g,
15- '/'
16- ) ;
14+ basePath = path . join ( require . resolve ( 'webpack-dev-server' ) , '..' , '..' ) ;
1715} catch {
1816 runCLITest = describe . skip ;
1917}
@@ -39,7 +37,9 @@ runCLITest('CLI', () => {
3937 '$1 Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT'
4038 )
4139 . replace ( / w e b p a c k [ ^ ) ] + / g, 'webpack x.x.x' )
40+ . replace ( new RegExp ( quotemeta ( basePath . replace ( / \\ / g, '/' ) ) , 'g' ) , 'Xdir' )
4241 . replace ( new RegExp ( quotemeta ( basePath ) , 'g' ) , 'Xdir' )
42+ . replace ( / [ \\ / ] s t a t i c / , '/static' )
4343 . replace ( / ( H a s h : ) [ a - z 0 - 9 ] + / g, '$1 X' )
4444 . replace ( / d e p e n d e n c i e s : X m s / g, '' )
4545 . 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', () => {
178178 it ( 'should log public path' , ( done ) => {
179179 testBin (
180180 false ,
181- resolve ( __dirname , '../fixtures/dev-public-path/webpack.config.js' )
181+ path . resolve ( __dirname , '../fixtures/dev-public-path/webpack.config.js' )
182182 )
183183 . then ( ( output ) => {
184184 expect ( output . exitCode ) . toEqual ( 0 ) ;
@@ -194,10 +194,35 @@ runCLITest('CLI', () => {
194194 } ) ;
195195 } ) ;
196196
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+
197222 it ( 'should accept the promise function of webpack.config.js' , ( done ) => {
198223 testBin (
199224 false ,
200- resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
225+ path . resolve ( __dirname , '../fixtures/promise-config/webpack.config.js' )
201226 )
202227 . then ( ( output ) => {
203228 expect ( output . exitCode ) . toEqual ( 0 ) ;
@@ -211,8 +236,8 @@ runCLITest('CLI', () => {
211236 } ) ;
212237
213238 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' ) ;
216241 const cp = execa ( 'node' , [ cliPath ] , { cwd : examplePath } ) ;
217242
218243 cp . stderr . on ( 'data' , ( data ) => {
@@ -231,8 +256,8 @@ runCLITest('CLI', () => {
231256 } ) ;
232257
233258 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' ) ;
236261 const cp = execa ( 'node' , [ cliPath ] , { cwd } ) ;
237262
238263 let killed = false ;
@@ -253,8 +278,8 @@ runCLITest('CLI', () => {
253278 } ) ;
254279
255280 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' ) ;
258283 const cp = execa ( 'node' , [ cliPath , '--stdin' ] , { cwd : examplePath } ) ;
259284
260285 cp . stderr . on ( 'data' , ( data ) => {
@@ -274,8 +299,8 @@ runCLITest('CLI', () => {
274299 } ) ;
275300
276301 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' ) ;
279304 const cp = execa ( 'node' , [ cliPath , '--stdin' ] , { cwd } ) ;
280305
281306 let killed = false ;
@@ -299,8 +324,8 @@ runCLITest('CLI', () => {
299324 // TODO: do not skip after @webpack -cli/serve passes null port by default
300325 // https://github.com/webpack/webpack-cli/pull/2126
301326 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' ) ;
304329
305330 const cp = execa ( 'node' , [ cliPath , '--colors=false' ] , { cwd } ) ;
306331 const cp2 = execa ( 'node' , [ cliPath , '--colors=false' ] , { cwd } ) ;
0 commit comments