Skip to content

Commit 71efc0d

Browse files
committed
update NoEmitOnErrorsPlugin to recognize child compilation errors, add tests
1 parent aaaa4c3 commit 71efc0d

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

lib/NoEmitOnErrorsPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
class NoEmitOnErrorsPlugin {
88
apply(compiler) {
99
compiler.plugin("should-emit", (compilation) => {
10-
if(compilation.errors.length > 0)
10+
if(compilation.getStats().hasErrors())
1111
return false;
1212
});
1313
compiler.plugin("compilation", (compilation) => {
1414
compilation.plugin("should-record", () => {
15-
if(compilation.errors.length > 0)
15+
if(compilation.getStats().hasErrors())
1616
return false;
1717
});
1818
});

test/StatsTestCases.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("StatsTestCases", () => {
5252
if(/error$/.test(testName)) {
5353
stats.hasErrors().should.be.equal(true);
5454
} else if(stats.hasErrors()) {
55-
done(new Error(stats.toJson().errors.join("\n\n")));
55+
return done(new Error(stats.toJson().errors.join("\n\n")));
5656
}
5757

5858
let toStringOptions = {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
var SingleEntryPlugin = require("../../../lib/SingleEntryPlugin");
4+
5+
/**
6+
* Runs a child compilation which produces an error in order to test that NoEmitErrorsPlugin
7+
* recognizes errors within child compilations.
8+
*/
9+
module.exports = class TestChildCompilationFailurePlugin {
10+
11+
constructor(output) {
12+
this.output = output;
13+
}
14+
15+
apply(compiler) {
16+
compiler.plugin("make", (compilation, cb) => {
17+
const child = compilation.createChildCompiler("child", this.output);
18+
child.plugin("compilation", childCompilation => {
19+
childCompilation.errors.push(new Error("forced error"));
20+
});
21+
child.apply(new SingleEntryPlugin(compiler.options.context, compiler.options.entry, "child"));
22+
child.runAsChild(cb);
23+
});
24+
}
25+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Hash: fb0670ebd6884ae658dc
2+
Time: Xms
3+
Asset Size Chunks Chunk Names
4+
child.js 2.47 kB
5+
bundle.js 2.47 kB 0 main
6+
[0] (webpack)/test/statsCases/no-emit-on-errors-plugin-with-child-error/index.js 0 bytes {0} [built]
7+
Child child:
8+
Asset Size Chunks Chunk Names
9+
child.js 2.47 kB 0 child
10+
[0] (webpack)/test/statsCases/no-emit-on-errors-plugin-with-child-error/index.js 0 bytes {0} [built]
11+
12+
ERROR in forced error

test/statsCases/no-emit-on-errors-plugin-with-child-error/index.js

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
3+
var NoEmitOnErrorsPlugin = require("../../../lib/NoEmitOnErrorsPlugin");
4+
var TestChildCompilationFailurePlugin = require("./TestChildCompilationFailurePlugin");
5+
6+
module.exports = {
7+
entry: "./index",
8+
output: {
9+
filename: "bundle.js"
10+
},
11+
plugins: [
12+
new NoEmitOnErrorsPlugin(),
13+
new TestChildCompilationFailurePlugin({
14+
filename: "child.js"
15+
})
16+
]
17+
};

0 commit comments

Comments
 (0)