/
no-hot.test.js
48 lines (44 loc) · 1.9 KB
/
no-hot.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
'use strict';
const { run } = require('../utils/test-utils');
const { stat, readFile } = require('fs');
const { resolve } = require('path');
const { yellow } = require('colorette');
describe('no-hot flag', () => {
it('should be successful when --no-hot is passed', (done) => {
const { stderr, stdout } = run(__dirname, ['--no-hot']);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(stdout).not.toContain('webpack/runtime/hot module replacement');
stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => {
expect(err).toBe(null);
// check for absence of special functions invoked by HMR plugin only
expect(data).not.toContain('/* webpack/runtime/hot module replacement */');
done();
});
});
it('should warn when --hot and --no-hot both are passed', (done) => {
const { stderr, stdout } = run(__dirname, ['--hot', '--no-hot']);
expect(stderr).toContain(
`[webpack-cli] ${yellow(
'You provided both --hot and --no-hot. We will use only the last of these flags that you provided in your CLI arguments',
)}`,
);
expect(stdout).toBeTruthy();
stat(resolve(__dirname, './bin/main.js'), (err, stats) => {
expect(err).toBe(null);
expect(stats.isFile()).toBe(true);
done();
});
readFile(resolve(__dirname, './bin/main.js'), 'utf-8', (err, data) => {
expect(err).toBe(null);
// check for absence of special functions invoked by HMR plugin only
expect(data).not.toContain('/* webpack/runtime/hot module replacement */');
done();
});
});
});