-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
progress-option.test.js
58 lines (49 loc) · 1.68 KB
/
progress-option.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
'use strict';
const webpack = require('webpack');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map')['progress-option'];
describe('progress', () => {
describe('output', () => {
let mockStderr;
beforeAll(() => {
mockStderr = jest
.spyOn(process.stderr, 'write')
.mockImplementation(() => {});
});
it('should show percentage progress without profile data', (done) => {
const compiler = webpack(config);
const server = new Server(compiler, {
port,
progress: true,
quiet: true,
});
compiler.hooks.done.tap('webpack-dev-server', () => {
const calls = mockStderr.mock.calls;
mockStderr.mockRestore();
let foundProgress = false;
let foundProfile = false;
calls.forEach((call) => {
if (call[0].includes('0% compiling')) {
foundProgress = true;
}
// this is an indicator that the profile option is enabled,
// so we should expect to not find it in stderr since it is not enabled
if (call[0].includes('ms after chunk modules optimization')) {
foundProfile = true;
}
});
expect(foundProgress).toBeTruthy();
expect(foundProfile).toBeFalsy();
server.close(done);
});
compiler.run(() => {});
const app = server.listen(port, 'localhost');
app.on('progress-update', ({ percent, msg }) => {
expect(percent).toBeGreaterThanOrEqual(0);
expect(percent).toBeLessThanOrEqual(100);
expect(typeof msg).toEqual('string');
});
});
});
});