@@ -15,6 +15,8 @@ const baseDevConfig = {
15
15
static : false ,
16
16
} ;
17
17
18
+ const createServer = ( compiler , options ) => new Server ( options , compiler ) ;
19
+
18
20
describe ( 'Server' , ( ) => {
19
21
describe ( 'sockjs' , ( ) => {
20
22
it ( 'add decorateConnection' , ( ) => {
@@ -48,7 +50,7 @@ describe('Server', () => {
48
50
49
51
it ( 'add hot option' , ( done ) => {
50
52
const compiler = webpack ( config ) ;
51
- const server = new Server (
53
+ const server = createServer (
52
54
compiler ,
53
55
Object . assign ( { } , baseDevConfig , {
54
56
hot : true ,
@@ -67,7 +69,7 @@ describe('Server', () => {
67
69
68
70
it ( 'add hot-only option' , ( done ) => {
69
71
const compiler = webpack ( config ) ;
70
- const server = new Server (
72
+ const server = createServer (
71
73
compiler ,
72
74
Object . assign ( { } , baseDevConfig , {
73
75
hot : 'only' ,
@@ -87,7 +89,7 @@ describe('Server', () => {
87
89
88
90
it ( 'test server error reporting' , ( ) => {
89
91
const compiler = webpack ( config ) ;
90
- const server = new Server ( compiler , baseDevConfig ) ;
92
+ const server = createServer ( compiler , baseDevConfig ) ;
91
93
92
94
const emitError = ( ) => server . server . emit ( 'error' , new Error ( 'Error !!!' ) ) ;
93
95
@@ -114,7 +116,7 @@ describe('Server', () => {
114
116
} ) ;
115
117
116
118
const compiler = webpack ( config ) ;
117
- const server = new Server ( compiler , baseDevConfig ) ;
119
+ const server = createServer ( compiler , baseDevConfig ) ;
118
120
119
121
compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
120
122
const output = server . getStats ( s ) ;
@@ -152,7 +154,7 @@ describe('Server', () => {
152
154
host : 'bad.host' ,
153
155
} ;
154
156
155
- server = new Server ( compiler , options ) ;
157
+ server = createServer ( compiler , options ) ;
156
158
157
159
if ( ! server . checkHost ( headers ) ) {
158
160
throw new Error ( "Validation didn't fail" ) ;
@@ -166,7 +168,7 @@ describe('Server', () => {
166
168
const headers = {
167
169
host : 'localhost' ,
168
170
} ;
169
- server = new Server ( compiler , options ) ;
171
+ server = createServer ( compiler , options ) ;
170
172
if ( ! server . checkHost ( headers ) ) {
171
173
throw new Error ( "Validation didn't fail" ) ;
172
174
}
@@ -181,7 +183,7 @@ describe('Server', () => {
181
183
host : '127.0.0.1' ,
182
184
} ;
183
185
184
- server = new Server ( compiler , options ) ;
186
+ server = createServer ( compiler , options ) ;
185
187
186
188
if ( ! server . checkHost ( headers ) ) {
187
189
throw new Error ( "Validation didn't fail" ) ;
@@ -200,7 +202,7 @@ describe('Server', () => {
200
202
'[ad42::1de2:54c2:c2fa:1234]:8080' ,
201
203
] ;
202
204
203
- server = new Server ( compiler , options ) ;
205
+ server = createServer ( compiler , options ) ;
204
206
205
207
tests . forEach ( ( test ) => {
206
208
const headers = { host : test } ;
@@ -220,7 +222,7 @@ describe('Server', () => {
220
222
host : 'test.hostname:80' ,
221
223
} ;
222
224
223
- server = new Server ( compiler , options ) ;
225
+ server = createServer ( compiler , options ) ;
224
226
225
227
if ( server . checkHost ( headers ) ) {
226
228
throw new Error ( "Validation didn't fail" ) ;
@@ -234,7 +236,7 @@ describe('Server', () => {
234
236
const headers = {
235
237
origin : 'https://test.host' ,
236
238
} ;
237
- server = new Server ( compiler , options ) ;
239
+ server = createServer ( compiler , options ) ;
238
240
if ( ! server . checkOrigin ( headers ) ) {
239
241
throw new Error ( "Validation didn't fail" ) ;
240
242
}
@@ -244,7 +246,7 @@ describe('Server', () => {
244
246
it ( 'should allow hosts in firewall' , ( ) => {
245
247
const tests = [ 'test.host' , 'test2.host' , 'test3.host' ] ;
246
248
const options = { firewall : tests } ;
247
- server = new Server ( compiler , options ) ;
249
+ server = createServer ( compiler , options ) ;
248
250
tests . forEach ( ( test ) => {
249
251
const headers = { host : test } ;
250
252
if ( ! server . checkHost ( headers ) ) {
@@ -255,7 +257,7 @@ describe('Server', () => {
255
257
256
258
it ( 'should allow hosts that pass a wildcard in firewall' , ( ) => {
257
259
const options = { firewall : [ '.example.com' ] } ;
258
- server = new Server ( compiler , options ) ;
260
+ server = createServer ( compiler , options ) ;
259
261
const tests = [
260
262
'www.example.com' ,
261
263
'subdomain.example.com' ,
@@ -278,7 +280,7 @@ describe('Server', () => {
278
280
describe ( 'Testing callback functions on calling invalidate without callback' , ( ) => {
279
281
it ( 'should use default `noop` callback' , ( done ) => {
280
282
const compiler = webpack ( config ) ;
281
- const server = new Server ( compiler , baseDevConfig ) ;
283
+ const server = createServer ( compiler , baseDevConfig ) ;
282
284
283
285
server . invalidate ( ) ;
284
286
expect ( server . middleware . context . callbacks . length ) . toEqual ( 1 ) ;
@@ -295,7 +297,7 @@ describe('Server', () => {
295
297
it ( 'should use `callback` function' , ( done ) => {
296
298
const compiler = webpack ( config ) ;
297
299
const callback = jest . fn ( ) ;
298
- const server = new Server ( compiler , baseDevConfig ) ;
300
+ const server = createServer ( compiler , baseDevConfig ) ;
299
301
300
302
server . invalidate ( callback ) ;
301
303
0 commit comments