-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
/
ProgressPlugin.test.js
111 lines (90 loc) · 2.58 KB
/
ProgressPlugin.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
101
102
103
104
105
106
107
108
109
110
111
"use strict";
const _ = require("lodash");
const path = require("path");
const MemoryFs = require("memory-fs");
const captureStdio = require("./helpers/captureStdio");
let webpack;
describe("ProgressPlugin", function() {
let stderr;
beforeEach(() => {
stderr = captureStdio(process.stderr, true);
webpack = require("../");
});
afterEach(() => {
stderr && stderr.restore();
});
it("should not contain NaN as a percentage when it is applied to MultiCompiler", () => {
const compiler = createMultiCompiler();
return RunCompilerAsync(compiler).then(() => {
expect(stderr.toString()).toContain("%");
expect(stderr.toString()).not.toContain("NaN");
});
});
it("should not print lines longer than stderr.columns", () => {
const compiler = createSimpleCompiler();
process.stderr.columns = 31;
return RunCompilerAsync(compiler).then(() => {
const logs = getLogs(stderr.toString());
expect(logs.length).toBeGreaterThan(20);
logs.forEach(log => expect(log.length).toBeLessThanOrEqual(30));
expect(logs).toContain(
"77% ...timization ...nksPlugin",
"trims each detail string equally"
);
expect(logs).toContain(
"10% building ...dules 0 active",
"remove empty arguments"
);
expect(logs).toContain(
"10% building ...dules 1 active",
"omit arguments when no space"
);
expect(logs).toContain("93% ...hunk asset optimization");
expect(logs).toContain("100%");
});
});
it("should handle when stderr.columns is undefined", () => {
const compiler = createSimpleCompiler();
process.stderr.columns = undefined;
return RunCompilerAsync(compiler).then(() => {
const logs = getLogs(stderr.toString());
expect(logs.length).toBeGreaterThan(20);
expect(_.maxBy(logs, "length").length).toBeGreaterThan(50);
});
});
});
const createMultiCompiler = () => {
const compiler = webpack([
{
context: path.join(__dirname, "fixtures"),
entry: "./a.js"
},
{
context: path.join(__dirname, "fixtures"),
entry: "./b.js"
}
]);
compiler.outputFileSystem = new MemoryFs();
new webpack.ProgressPlugin().apply(compiler);
return compiler;
};
const createSimpleCompiler = () => {
const compiler = webpack({
context: path.join(__dirname, "fixtures"),
entry: "./a.js"
});
compiler.outputFileSystem = new MemoryFs();
new webpack.ProgressPlugin().apply(compiler);
return compiler;
};
const getLogs = logsStr => logsStr.split(/\r/).filter(v => !(v === " "));
const RunCompilerAsync = compiler =>
new Promise((resolve, reject) => {
compiler.run(err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});