Skip to content

Commit 93c85ca

Browse files
committed
test: update tests
1 parent 549b0c2 commit 93c85ca

File tree

6 files changed

+55
-49
lines changed

6 files changed

+55
-49
lines changed

test/helpers/test-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function startFullSetup(config, options, done) {
1818

1919
const compiler = webpack(config);
2020

21-
server = new Server(compiler, options);
21+
server = new Server(options, compiler);
2222

2323
let port;
2424
if (Object.prototype.hasOwnProperty.call(options, 'port')) {

test/server/Server.test.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const baseDevConfig = {
1515
static: false,
1616
};
1717

18+
const createServer = (compiler, options) => new Server(options, compiler);
19+
1820
describe('Server', () => {
1921
describe('sockjs', () => {
2022
it('add decorateConnection', () => {
@@ -48,7 +50,7 @@ describe('Server', () => {
4850

4951
it('add hot option', (done) => {
5052
const compiler = webpack(config);
51-
const server = new Server(
53+
const server = createServer(
5254
compiler,
5355
Object.assign({}, baseDevConfig, {
5456
hot: true,
@@ -67,7 +69,7 @@ describe('Server', () => {
6769

6870
it('add hot-only option', (done) => {
6971
const compiler = webpack(config);
70-
const server = new Server(
72+
const server = createServer(
7173
compiler,
7274
Object.assign({}, baseDevConfig, {
7375
hot: 'only',
@@ -87,7 +89,7 @@ describe('Server', () => {
8789

8890
it('test server error reporting', () => {
8991
const compiler = webpack(config);
90-
const server = new Server(compiler, baseDevConfig);
92+
const server = createServer(compiler, baseDevConfig);
9193

9294
const emitError = () => server.server.emit('error', new Error('Error !!!'));
9395

@@ -114,7 +116,7 @@ describe('Server', () => {
114116
});
115117

116118
const compiler = webpack(config);
117-
const server = new Server(compiler, baseDevConfig);
119+
const server = createServer(compiler, baseDevConfig);
118120

119121
compiler.hooks.done.tap('webpack-dev-server', (s) => {
120122
const output = server.getStats(s);
@@ -152,7 +154,7 @@ describe('Server', () => {
152154
host: 'bad.host',
153155
};
154156

155-
server = new Server(compiler, options);
157+
server = createServer(compiler, options);
156158

157159
if (!server.checkHost(headers)) {
158160
throw new Error("Validation didn't fail");
@@ -166,7 +168,7 @@ describe('Server', () => {
166168
const headers = {
167169
host: 'localhost',
168170
};
169-
server = new Server(compiler, options);
171+
server = createServer(compiler, options);
170172
if (!server.checkHost(headers)) {
171173
throw new Error("Validation didn't fail");
172174
}
@@ -181,7 +183,7 @@ describe('Server', () => {
181183
host: '127.0.0.1',
182184
};
183185

184-
server = new Server(compiler, options);
186+
server = createServer(compiler, options);
185187

186188
if (!server.checkHost(headers)) {
187189
throw new Error("Validation didn't fail");
@@ -200,7 +202,7 @@ describe('Server', () => {
200202
'[ad42::1de2:54c2:c2fa:1234]:8080',
201203
];
202204

203-
server = new Server(compiler, options);
205+
server = createServer(compiler, options);
204206

205207
tests.forEach((test) => {
206208
const headers = { host: test };
@@ -220,7 +222,7 @@ describe('Server', () => {
220222
host: 'test.hostname:80',
221223
};
222224

223-
server = new Server(compiler, options);
225+
server = createServer(compiler, options);
224226

225227
if (server.checkHost(headers)) {
226228
throw new Error("Validation didn't fail");
@@ -234,7 +236,7 @@ describe('Server', () => {
234236
const headers = {
235237
origin: 'https://test.host',
236238
};
237-
server = new Server(compiler, options);
239+
server = createServer(compiler, options);
238240
if (!server.checkOrigin(headers)) {
239241
throw new Error("Validation didn't fail");
240242
}
@@ -244,7 +246,7 @@ describe('Server', () => {
244246
it('should allow hosts in firewall', () => {
245247
const tests = ['test.host', 'test2.host', 'test3.host'];
246248
const options = { firewall: tests };
247-
server = new Server(compiler, options);
249+
server = createServer(compiler, options);
248250
tests.forEach((test) => {
249251
const headers = { host: test };
250252
if (!server.checkHost(headers)) {
@@ -255,7 +257,7 @@ describe('Server', () => {
255257

256258
it('should allow hosts that pass a wildcard in firewall', () => {
257259
const options = { firewall: ['.example.com'] };
258-
server = new Server(compiler, options);
260+
server = createServer(compiler, options);
259261
const tests = [
260262
'www.example.com',
261263
'subdomain.example.com',
@@ -278,7 +280,7 @@ describe('Server', () => {
278280
describe('Testing callback functions on calling invalidate without callback', () => {
279281
it('should use default `noop` callback', (done) => {
280282
const compiler = webpack(config);
281-
const server = new Server(compiler, baseDevConfig);
283+
const server = createServer(compiler, baseDevConfig);
282284

283285
server.invalidate();
284286
expect(server.middleware.context.callbacks.length).toEqual(1);
@@ -295,7 +297,7 @@ describe('Server', () => {
295297
it('should use `callback` function', (done) => {
296298
const compiler = webpack(config);
297299
const callback = jest.fn();
298-
const server = new Server(compiler, baseDevConfig);
300+
const server = createServer(compiler, baseDevConfig);
299301

300302
server.invalidate(callback);
301303

0 commit comments

Comments
 (0)