Skip to content

Commit 9db03d8

Browse files
committed
test(Server): add addEntries tests
1 parent 0f7abdf commit 9db03d8

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

test/Server.test.js

+59
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const { relative } = require('path');
34
const webpack = require('webpack');
45
const Server = require('../lib/Server');
56
const config = require('./fixtures/simple-config/webpack.config');
@@ -16,6 +17,64 @@ const allStats = [
1617
];
1718

1819
describe('Server', () => {
20+
describe('addEntries', () => {
21+
it('add hot option', () => {
22+
return new Promise((res) => {
23+
// eslint-disable-next-line
24+
const Server = require('../lib/Server');
25+
const compiler = webpack(config);
26+
const server = new Server(compiler, {
27+
hot: true,
28+
});
29+
30+
expect(
31+
server.middleware.context.compiler.options.entry.map((p) => {
32+
return relative('.', p);
33+
})
34+
).toMatchSnapshot();
35+
expect(
36+
server.middleware.context.compiler.options.plugins
37+
).toMatchSnapshot();
38+
39+
compiler.hooks.done.tap('webpack-dev-server', () => {
40+
server.close(() => {
41+
res();
42+
});
43+
});
44+
45+
compiler.run(() => {});
46+
});
47+
});
48+
49+
it('add hotOnly option', () => {
50+
return new Promise((res) => {
51+
// eslint-disable-next-line
52+
const Server = require('../lib/Server');
53+
const compiler = webpack(config);
54+
const server = new Server(compiler, {
55+
hotOnly: true,
56+
});
57+
58+
expect(
59+
server.middleware.context.compiler.options.entry.map((p) => {
60+
return relative('.', p);
61+
})
62+
).toMatchSnapshot();
63+
expect(
64+
server.middleware.context.compiler.options.plugins
65+
).toMatchSnapshot();
66+
67+
compiler.hooks.done.tap('webpack-dev-server', () => {
68+
server.close(() => {
69+
res();
70+
});
71+
});
72+
73+
compiler.run(() => {});
74+
});
75+
});
76+
});
77+
1978
// issue: https://github.com/webpack/webpack-dev-server/issues/1724
2079
describe('express.static.mine.types', () => {
2180
beforeEach(() => {
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Server addEntries add hot option 1`] = `
4+
Array [
5+
"client/index.js?http:/localhost",
6+
"node_modules/webpack/hot/dev-server.js",
7+
"foo.js",
8+
]
9+
`;
10+
11+
exports[`Server addEntries add hot option 2`] = `
12+
Array [
13+
HotModuleReplacementPlugin {
14+
"fullBuildTimeout": 200,
15+
"multiStep": undefined,
16+
"options": Object {},
17+
"requestTimeout": 10000,
18+
},
19+
]
20+
`;
21+
22+
exports[`Server addEntries add hotOnly option 1`] = `
23+
Array [
24+
"client/index.js?http:/localhost",
25+
"node_modules/webpack/hot/only-dev-server.js",
26+
"foo.js",
27+
]
28+
`;
29+
30+
exports[`Server addEntries add hotOnly option 2`] = `
31+
Array [
32+
HotModuleReplacementPlugin {
33+
"fullBuildTimeout": 200,
34+
"multiStep": undefined,
35+
"options": Object {},
36+
"requestTimeout": 10000,
37+
},
38+
]
39+
`;

0 commit comments

Comments
 (0)