/
info-verbosity-off.test.js
100 lines (84 loc) · 2.35 KB
/
info-verbosity-off.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use strict";
jest.setTimeout(10e6);
/* eslint-disable node/no-unsupported-features */
/* eslint-disable node/no-unsupported-features/es-syntax */
const fs = require("fs");
const path = require("path");
const {
extractSummary,
extractHash,
appendDataIfFileExists,
runAndGetWatchProc,
copyFile
} = require("../../../testUtils");
const fileToChange = "index.js";
const fileToChangePath = path.resolve(__dirname, fileToChange);
var copyFilePath;
// create copy of "index.js" => "index_copy.js"
beforeEach(() => {
copyFilePath = copyFile(__dirname, fileToChange);
});
afterEach(() => {
try {
// subsequent test-case runs won't pass as snapshot is not matched
// hence, deleting the file as it is modified by the test
fs.unlinkSync(fileToChangePath);
} catch (e) {
console.warn("could not remove the file:" + fileToChangePath + "\n" + e.message);
} finally {
fs.renameSync(copyFilePath, fileToChangePath);
}
});
test.skip("info-verbosity-off", done => {
var webpackProc = runAndGetWatchProc(__dirname, [
"--entry ",
"./index.js",
"--config",
"./webpack.config.js",
"--output-filename",
"[name].js",
"--output-chunk-filename",
"[id].chunk.js",
"--target",
"async-node",
"--watch",
"--info-verbosity",
"none"
]);
// info-verbosity none spits the output in one go.
// So we only need to keep a track of when we change the files
// 1. Hash and other info
// 2. (file changed) Hash and other info
var chunkNumber = 0;
var hash1, hash2;
var summary;
webpackProc.stdout.on("data", data => {
data = data.toString();
chunkNumber++;
// We get webpack output after running test
// Since we are running the webpack in watch mode, changing file will generate additional output
// First time output will be validated fully
// Hash of the The subsequent output will be tested against that of first time output
switch (chunkNumber) {
case 1:
hash1 = extractHash(data);
summary = extractSummary(data);
expect(summary).toMatchSnapshot();
// change file
appendDataIfFileExists(__dirname, fileToChange, "//junk-comment");
break;
case 2:
hash2 = extractHash(data);
expect(hash2.hash).not.toBe(hash1.hash);
webpackProc.kill();
done();
break;
default:
break;
}
});
webpackProc.stderr.on("data", error => {
// fail test case if there is any error
done(error.toString());
});
});