@@ -6,42 +6,7 @@ const internalIp = require('internal-ip');
6
6
const testBin = require ( '../helpers/test-bin' ) ;
7
7
const isWebpack5 = require ( '../helpers/isWebpack5' ) ;
8
8
9
- // skip if webpack-dev-server is not linked
10
- let runCLITest = describe ;
11
- let basePath ;
12
-
13
- try {
14
- basePath = path . join ( require . resolve ( 'webpack-dev-server' ) , '..' , '..' ) ;
15
- } catch {
16
- runCLITest = describe . skip ;
17
- }
18
-
19
- runCLITest ( 'CLI' , ( ) => {
20
- /* Based on webpack/test/StatsTestCases.test.js */
21
- /**
22
- * Escapes regular expression metacharacters
23
- * @param {string } str String to quote
24
- * @returns {string } Escaped string
25
- */
26
- const quotemeta = ( str ) => str . replace ( / [ - [ \] \\ / { } ( ) * + ? . ^ $ | ] / g, '\\$&' ) ;
27
-
28
- const normalizeOutput = ( output ) =>
29
- output
30
- // eslint-disable-next-line no-control-regex
31
- . replace ( / \u001b \[ [ 0 - 9 ; ] * m / g, '' )
32
- . replace ( / [ . 0 - 9 ] + ( \s ? ) ( m s | K i B | b y t e s ) / g, 'X$1$2' )
33
- . replace (
34
- / ( B u i l t a t : ) ( .* ) $ / gm,
35
- '$1 Thu Jan 01 1970 <CLR=BOLD>00:00:00</CLR> GMT'
36
- )
37
- . replace ( / w e b p a c k [ ^ ) ] + / g, 'webpack x.x.x' )
38
- . replace ( new RegExp ( quotemeta ( basePath . replace ( / \\ / g, '/' ) ) , 'g' ) , 'Xdir' )
39
- . replace ( new RegExp ( quotemeta ( basePath ) , 'g' ) , 'Xdir' )
40
- . replace ( / [ \\ / ] p u b l i c / , '/public' )
41
- . replace ( / ( H a s h : ) [ a - z 0 - 9 ] + / g, '$1 X' )
42
- . replace ( / d e p e n d e n c i e s : X m s / g, '' )
43
- . replace ( / , a d d i t i o n a l r e s o l v i n g : X m s / g, '' ) ;
44
-
9
+ describe ( 'CLI' , ( ) => {
45
10
const webpack4Test = isWebpack5 ? it . skip : it ;
46
11
const webpack5Test = isWebpack5 ? it : it . skip ;
47
12
@@ -66,22 +31,21 @@ runCLITest('CLI', () => {
66
31
} ) ;
67
32
68
33
webpack5Test ( '--hot webpack 5' , ( done ) => {
69
- // host doesn't default to `localhost`
70
- testBin ( '--hot --host localhost ' )
34
+ // need detailed stats to check for 'dev-server.js'
35
+ testBin ( '--hot --stats=detailed ' )
71
36
. then ( ( output ) => {
72
37
expect ( output . exitCode ) . toEqual ( 0 ) ;
73
- expect ( normalizeOutput ( output . stderr ) ) . toMatchSnapshot ( ) ;
38
+ expect ( output . stderr ) . toContain ( 'webpack/hot/dev-server.js' ) ;
74
39
done ( ) ;
75
40
} )
76
41
. catch ( done ) ;
77
42
} ) ;
78
43
79
44
webpack5Test ( '--no-hot webpack 5' , ( done ) => {
80
- // host doesn't default to `localhost`
81
- testBin ( '--no-hot --host localhost' )
45
+ testBin ( '--no-hot --stats=detailed' )
82
46
. then ( ( output ) => {
83
47
expect ( output . exitCode ) . toEqual ( 0 ) ;
84
- expect ( normalizeOutput ( output . stderr ) ) . toMatchSnapshot ( ) ;
48
+ expect ( output . stderr ) . not . toContain ( 'webpack/hot/dev-server.js' ) ;
85
49
done ( ) ;
86
50
} )
87
51
. catch ( done ) ;
@@ -119,9 +83,7 @@ runCLITest('CLI', () => {
119
83
. catch ( done ) ;
120
84
} ) ;
121
85
122
- // TODO: enable after fixing url bug with undefined host
123
- // https://github.com/webpack/webpack-dev-server/pull/2992#discussion_r571360196
124
- it . skip ( 'unspecified host and port' , ( done ) => {
86
+ it ( 'unspecified host and port' , ( done ) => {
125
87
testBin ( '' )
126
88
. then ( ( output ) => {
127
89
expect ( / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + / . test ( output . stderr ) ) . toEqual ( true ) ;
0 commit comments