webpack/test/statsCases/no-emit-on-errors-plugin-wi.../TestChildCompilationFailure...

26 lines
800 B
JavaScript

"use strict";
var EntryPlugin = require("../../../lib/EntryPlugin");
/**
* Runs a child compilation which produces an error in order to test that NoEmitErrorsPlugin
* recognizes errors within child compilations.
*/
module.exports = class TestChildCompilationFailurePlugin {
constructor(output) {
this.output = output;
}
apply(compiler) {
compiler.hooks.make.tapAsync("TestChildCompilationFailurePlugin", (compilation, cb) => {
const child = compilation.createChildCompiler("child", this.output);
child.hooks.compilation.tap("TestChildCompilationFailurePlugin", childCompilation => {
childCompilation.errors.push(new Error("forced error"));
});
new EntryPlugin(compiler.options.context, compiler.options.entry, "child").apply(child);
child.runAsChild(cb);
});
}
};