Skip to content

Commit 468e45f

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

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-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, sep } = 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).split(sep);
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).split(sep);
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(() => {
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Server addEntries add hot option 1`] = `
4+
Array [
5+
Array [
6+
"client",
7+
"index.js?http:",
8+
"localhost",
9+
],
10+
Array [
11+
"node_modules",
12+
"webpack",
13+
"hot",
14+
"dev-server.js",
15+
],
16+
Array [
17+
"foo.js",
18+
],
19+
]
20+
`;
21+
22+
exports[`Server addEntries add hot option 2`] = `
23+
Array [
24+
HotModuleReplacementPlugin {
25+
"fullBuildTimeout": 200,
26+
"multiStep": undefined,
27+
"options": Object {},
28+
"requestTimeout": 10000,
29+
},
30+
]
31+
`;
32+
33+
exports[`Server addEntries add hotOnly option 1`] = `
34+
Array [
35+
Array [
36+
"client",
37+
"index.js?http:",
38+
"localhost",
39+
],
40+
Array [
41+
"node_modules",
42+
"webpack",
43+
"hot",
44+
"only-dev-server.js",
45+
],
46+
Array [
47+
"foo.js",
48+
],
49+
]
50+
`;
51+
52+
exports[`Server addEntries add hotOnly option 2`] = `
53+
Array [
54+
HotModuleReplacementPlugin {
55+
"fullBuildTimeout": 200,
56+
"multiStep": undefined,
57+
"options": Object {},
58+
"requestTimeout": 10000,
59+
},
60+
]
61+
`;

0 commit comments

Comments
 (0)