forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.test.js
73 lines (64 loc) · 1.82 KB
/
Server.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const webpack = require('webpack');
const Server = require('../lib/Server');
const config = require('./fixtures/simple-config/webpack.config');
const allStats = [
{},
// eslint-disable-next-line no-undefined
undefined,
false,
'errors-only',
{
assets: false,
},
];
describe('Server', () => {
it(`should cascade stats options`, () => {
return new Promise((resolve, reject) => {
(function iterate(stats, i) {
if (i === allStats.length) {
return resolve();
}
const prom = new Promise((res, rej) => {
const compiler = webpack(config);
const server = new Server(compiler, { stats });
compiler.hooks.done.tap('webpack-dev-server', (s) => {
const finalStats = JSON.stringify(server.getStats(s));
const defaultStats = JSON.stringify(
server._stats.toJson(Server.DEFAULT_STATS)
);
// If we're not over-riding stats configuration,
// we get the same result as the DEFAULT_STATS
if (!stats || !Object.keys(stats).length) {
try {
expect(finalStats).toBe(defaultStats);
} catch (e) {
rej(e);
}
} else {
try {
expect(finalStats).not.toBe(defaultStats);
} catch (e) {
rej(e);
}
}
server.close(() => {
res();
});
});
compiler.run(() => {});
server.listen(8080, 'localhost');
});
// Iterate to cover each case.
prom
.then(() => {
i += 1;
iterate(allStats[i], i);
})
.catch((e) => {
reject(e);
});
})(allStats[0], 0);
});
});
});