3
3
const path = require ( 'path' ) ;
4
4
const execa = require ( 'execa' ) ;
5
5
const internalIp = require ( 'internal-ip' ) ;
6
- const testBin = require ( '../helpers/test-bin' ) ;
6
+ const { testBin, normalizeStderr } = require ( '../helpers/test-bin' ) ;
7
+
8
+ const localIPv4 = internalIp . v4 . sync ( ) ;
9
+ const localIPv6 = internalIp . v6 . sync ( ) ;
7
10
8
11
describe ( 'CLI' , ( ) => {
9
12
it ( '--hot' , ( done ) => {
@@ -90,10 +93,11 @@ describe('CLI', () => {
90
93
. catch ( done ) ;
91
94
} ) ;
92
95
93
- it ( 'unspecified host and port' , ( done ) => {
96
+ it ( '-- host and -- port are unspecified ' , ( done ) => {
94
97
testBin ( '' )
95
98
. then ( ( output ) => {
96
- expect ( / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + / . test ( output . stderr ) ) . toEqual ( true ) ;
99
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
100
+
97
101
done ( ) ;
98
102
} )
99
103
. catch ( done ) ;
@@ -102,27 +106,28 @@ describe('CLI', () => {
102
106
it ( '--host 0.0.0.0 (IPv4)' , ( done ) => {
103
107
testBin ( '--host 0.0.0.0' )
104
108
. then ( ( output ) => {
105
- const localIP = internalIp . v4 . sync ( ) ;
109
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
106
110
107
- expect ( / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + / . test ( output . stderr ) ) . toEqual ( true ) ;
108
- expect (
109
- new RegExp ( `http://${ localIP } :[0-9]+/` ) . test ( output . stderr )
110
- ) . toEqual ( true ) ;
111
111
done ( ) ;
112
112
} )
113
113
. catch ( done ) ;
114
114
} ) ;
115
115
116
- // TODO search way how to tests it on github actions
117
- it . skip ( '--host :: (IPv6)' , ( done ) => {
116
+ it ( '--host :: (IPv6)' , ( done ) => {
118
117
testBin ( '--host ::' )
119
118
. then ( ( output ) => {
120
- const localIP = internalIp . v4 . sync ( ) ;
119
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
120
+
121
+ done ( ) ;
122
+ } )
123
+ . catch ( done ) ;
124
+ } ) ;
125
+
126
+ it ( '--host ::1 (IPv6)' , ( done ) => {
127
+ testBin ( '--host ::1' )
128
+ . then ( ( output ) => {
129
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
121
130
122
- expect ( / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + / . test ( output . stderr ) ) . toEqual ( true ) ;
123
- expect (
124
- new RegExp ( `http://${ localIP } :[0-9]+/` ) . test ( output . stderr )
125
- ) . toEqual ( true ) ;
126
131
done ( ) ;
127
132
} )
128
133
. catch ( done ) ;
@@ -131,16 +136,58 @@ describe('CLI', () => {
131
136
it ( '--host localhost' , ( done ) => {
132
137
testBin ( '--host localhost' )
133
138
. then ( ( output ) => {
134
- expect ( / h t t p : \/ \/ l o c a l h o s t : [ 0 - 9 ] + / . test ( output . stderr ) ) . toEqual ( true ) ;
139
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
140
+
135
141
done ( ) ;
136
142
} )
137
143
. catch ( done ) ;
138
144
} ) ;
139
145
140
- it ( '--port and --host ' , ( done ) => {
141
- testBin ( '--port 9999 -- host localhost ' )
146
+ it ( '--host 127.0.0.1 (IPv4) ' , ( done ) => {
147
+ testBin ( '--host 127.0.0.1 ' )
142
148
. then ( ( output ) => {
143
- expect ( / h t t p : \/ \/ l o c a l h o s t : 9 9 9 9 / . test ( output . stderr ) ) . toEqual ( true ) ;
149
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
150
+
151
+ done ( ) ;
152
+ } )
153
+ . catch ( done ) ;
154
+ } ) ;
155
+
156
+ it ( '--host 0:0:0:0:0:FFFF:7F00:0001 (IPv6)' , ( done ) => {
157
+ testBin ( '--host 0:0:0:0:0:FFFF:7F00:0001' )
158
+ . then ( ( output ) => {
159
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
160
+
161
+ done ( ) ;
162
+ } )
163
+ . catch ( done ) ;
164
+ } ) ;
165
+
166
+ it ( `--host ${ localIPv4 } (IPv4)` , ( done ) => {
167
+ testBin ( `--host ${ localIPv4 } ` )
168
+ . then ( ( output ) => {
169
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
170
+
171
+ done ( ) ;
172
+ } )
173
+ . catch ( done ) ;
174
+ } ) ;
175
+
176
+ it . skip ( `--host ${ localIPv6 } (IPv6)` , ( done ) => {
177
+ testBin ( `--host ${ localIPv6 } ` )
178
+ . then ( ( output ) => {
179
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
180
+
181
+ done ( ) ;
182
+ } )
183
+ . catch ( done ) ;
184
+ } ) ;
185
+
186
+ it ( '--host localhost --port 9999' , ( done ) => {
187
+ testBin ( '--host localhost --port 9999' )
188
+ . then ( ( output ) => {
189
+ expect ( normalizeStderr ( output . stderr ) ) . toMatchSnapshot ( 'stderr' ) ;
190
+
144
191
done ( ) ;
145
192
} )
146
193
. catch ( done ) ;
@@ -292,8 +339,6 @@ describe('CLI', () => {
292
339
} ) ;
293
340
} ) ;
294
341
295
- // TODO: do not skip after @webpack -cli/serve passes null port by default
296
- // https://github.com/webpack/webpack-cli/pull/2126
297
342
it . skip ( 'should use different random port when multiple instances are started on different processes' , ( done ) => {
298
343
const cliPath = path . resolve ( __dirname , '../../bin/webpack-dev-server.js' ) ;
299
344
const cwd = path . resolve ( __dirname , '../fixtures/cli' ) ;
0 commit comments