/
serve-basic.test.js
79 lines (65 loc) · 2.73 KB
/
serve-basic.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
74
75
76
77
78
79
'use strict';
const { yellow, options } = require('colorette');
const path = require('path');
const getPort = require('get-port');
const { runServe } = require('../../utils/test-utils');
const testPath = path.resolve(__dirname);
const usageText = 'webpack s | serve';
const descriptionText = 'Run the webpack Dev Server';
describe('basic serve usage', () => {
let port;
beforeEach(async () => {
port = await getPort();
});
const isWindows = process.platform === 'win32';
// TODO fix me on windows
if (isWindows) {
it('TODO: Fix on windows', () => {
expect(true).toBe(true);
});
return;
}
it('should respect the --no-color flag', async () => {
const { stdout, stderr } = await runServe(['--help', '--no-color'], __dirname);
options.enabled = true;
expect(stdout).not.toContain(yellow(usageText));
expect(stdout).toContain(descriptionText);
expect(stderr).toHaveLength(0);
});
it('should not invoke info subcommand', async () => {
const { stdout, stderr } = await runServe(['--client-log-level', 'info'], testPath);
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('hot/dev-server.js');
expect(stderr).toHaveLength(0);
});
it('compiles without flags', async () => {
const { stdout, stderr } = await runServe(['--port', port], testPath);
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('hot/dev-server.js');
expect(stderr).toHaveLength(0);
});
it('uses hot flag to alter bundle', async () => {
const { stdout, stderr } = await runServe(['--port', port, '--hot'], testPath);
expect(stdout).toContain('main.js');
expect(stdout).toContain('hot/dev-server.js');
expect(stderr).toHaveLength(0);
});
it('uses no-hot flag', async () => {
const { stdout, stderr } = await runServe(['--port', port, '--no-hot'], testPath);
expect(stdout).toContain('main.js');
expect(stdout).not.toContain('hot/dev-server.js');
expect(stderr).toHaveLength(0);
});
it('uses hot flag and progress flag', async () => {
const { stdout, stderr } = await runServe(['--port', port, '--hot', '--progress'], testPath);
expect(stdout).toContain('main.js');
expect(stdout).toContain('hot/dev-server.js');
// progress flag makes use of stderr
expect(stderr).not.toHaveLength(0);
});
it('throws error on unknown flag', async () => {
const { stdout, stderr } = await runServe(['--port', port, '--unknown-flag'], testPath);
expect(stdout).toHaveLength(0);
expect(stderr).toContain('Unknown argument: --unknown-flag');
});
});