@@ -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 ,
@@ -65,9 +67,36 @@ describe('Server', () => {
65
67
compiler . run ( ( ) => { } ) ;
66
68
} ) ;
67
69
70
+ // TODO: remove this after plugin support is published
71
+ it ( 'should create and run server with old parameters order' , ( done ) => {
72
+ const compiler = webpack ( config ) ;
73
+ const server = new Server ( compiler , baseDevConfig ) ;
74
+
75
+ getEntries ( server ) ;
76
+
77
+ compiler . hooks . done . tap ( 'webpack-dev-server' , ( ) => {
78
+ expect ( entries ) . toMatchSnapshot ( 'oldparam' ) ;
79
+ server . close ( done ) ;
80
+ } ) ;
81
+
82
+ compiler . run ( ( ) => { } ) ;
83
+ } ) ;
84
+
85
+ // TODO: remove this after plugin support is published
86
+ it ( 'should create and run server with MultiCompiler with old parameters order' , ( done ) => {
87
+ const compiler = webpack ( [ config , config ] ) ;
88
+ const server = new Server ( compiler , baseDevConfig ) ;
89
+
90
+ compiler . hooks . done . tap ( 'webpack-dev-server' , ( ) => {
91
+ server . close ( done ) ;
92
+ } ) ;
93
+
94
+ compiler . run ( ( ) => { } ) ;
95
+ } ) ;
96
+
68
97
it ( 'add hot-only option' , ( done ) => {
69
98
const compiler = webpack ( config ) ;
70
- const server = new Server (
99
+ const server = createServer (
71
100
compiler ,
72
101
Object . assign ( { } , baseDevConfig , {
73
102
hot : 'only' ,
@@ -87,7 +116,7 @@ describe('Server', () => {
87
116
88
117
it ( 'test server error reporting' , ( ) => {
89
118
const compiler = webpack ( config ) ;
90
- const server = new Server ( compiler , baseDevConfig ) ;
119
+ const server = createServer ( compiler , baseDevConfig ) ;
91
120
92
121
const emitError = ( ) => server . server . emit ( 'error' , new Error ( 'Error !!!' ) ) ;
93
122
@@ -114,7 +143,7 @@ describe('Server', () => {
114
143
} ) ;
115
144
116
145
const compiler = webpack ( config ) ;
117
- const server = new Server ( compiler , baseDevConfig ) ;
146
+ const server = createServer ( compiler , baseDevConfig ) ;
118
147
119
148
compiler . hooks . done . tap ( 'webpack-dev-server' , ( s ) => {
120
149
const output = server . getStats ( s ) ;
@@ -152,7 +181,7 @@ describe('Server', () => {
152
181
host : 'bad.host' ,
153
182
} ;
154
183
155
- server = new Server ( compiler , options ) ;
184
+ server = createServer ( compiler , options ) ;
156
185
157
186
if ( ! server . checkHost ( headers ) ) {
158
187
throw new Error ( "Validation didn't fail" ) ;
@@ -166,7 +195,7 @@ describe('Server', () => {
166
195
const headers = {
167
196
host : 'localhost' ,
168
197
} ;
169
- server = new Server ( compiler , options ) ;
198
+ server = createServer ( compiler , options ) ;
170
199
if ( ! server . checkHost ( headers ) ) {
171
200
throw new Error ( "Validation didn't fail" ) ;
172
201
}
@@ -181,7 +210,7 @@ describe('Server', () => {
181
210
host : '127.0.0.1' ,
182
211
} ;
183
212
184
- server = new Server ( compiler , options ) ;
213
+ server = createServer ( compiler , options ) ;
185
214
186
215
if ( ! server . checkHost ( headers ) ) {
187
216
throw new Error ( "Validation didn't fail" ) ;
@@ -200,7 +229,7 @@ describe('Server', () => {
200
229
'[ad42::1de2:54c2:c2fa:1234]:8080' ,
201
230
] ;
202
231
203
- server = new Server ( compiler , options ) ;
232
+ server = createServer ( compiler , options ) ;
204
233
205
234
tests . forEach ( ( test ) => {
206
235
const headers = { host : test } ;
@@ -220,7 +249,7 @@ describe('Server', () => {
220
249
host : 'test.hostname:80' ,
221
250
} ;
222
251
223
- server = new Server ( compiler , options ) ;
252
+ server = createServer ( compiler , options ) ;
224
253
225
254
if ( server . checkHost ( headers ) ) {
226
255
throw new Error ( "Validation didn't fail" ) ;
@@ -234,7 +263,7 @@ describe('Server', () => {
234
263
const headers = {
235
264
origin : 'https://test.host' ,
236
265
} ;
237
- server = new Server ( compiler , options ) ;
266
+ server = createServer ( compiler , options ) ;
238
267
if ( ! server . checkOrigin ( headers ) ) {
239
268
throw new Error ( "Validation didn't fail" ) ;
240
269
}
@@ -244,7 +273,7 @@ describe('Server', () => {
244
273
it ( 'should allow hosts in firewall' , ( ) => {
245
274
const tests = [ 'test.host' , 'test2.host' , 'test3.host' ] ;
246
275
const options = { firewall : tests } ;
247
- server = new Server ( compiler , options ) ;
276
+ server = createServer ( compiler , options ) ;
248
277
tests . forEach ( ( test ) => {
249
278
const headers = { host : test } ;
250
279
if ( ! server . checkHost ( headers ) ) {
@@ -255,7 +284,7 @@ describe('Server', () => {
255
284
256
285
it ( 'should allow hosts that pass a wildcard in firewall' , ( ) => {
257
286
const options = { firewall : [ '.example.com' ] } ;
258
- server = new Server ( compiler , options ) ;
287
+ server = createServer ( compiler , options ) ;
259
288
const tests = [
260
289
'www.example.com' ,
261
290
'subdomain.example.com' ,
@@ -278,7 +307,7 @@ describe('Server', () => {
278
307
describe ( 'Testing callback functions on calling invalidate without callback' , ( ) => {
279
308
it ( 'should use default `noop` callback' , ( done ) => {
280
309
const compiler = webpack ( config ) ;
281
- const server = new Server ( compiler , baseDevConfig ) ;
310
+ const server = createServer ( compiler , baseDevConfig ) ;
282
311
283
312
server . invalidate ( ) ;
284
313
expect ( server . middleware . context . callbacks . length ) . toEqual ( 1 ) ;
@@ -295,7 +324,7 @@ describe('Server', () => {
295
324
it ( 'should use `callback` function' , ( done ) => {
296
325
const compiler = webpack ( config ) ;
297
326
const callback = jest . fn ( ) ;
298
- const server = new Server ( compiler , baseDevConfig ) ;
327
+ const server = createServer ( compiler , baseDevConfig ) ;
299
328
300
329
server . invalidate ( callback ) ;
301
330
0 commit comments