Skip to content

Commit

Permalink
Merge pull request #8401 from shahkashani/fix-for-issue-8398
Browse files Browse the repository at this point in the history
Fix for #8398 - call failed-hook on compilation errors
  • Loading branch information
sokra committed Dec 30, 2018
2 parents 2e3e2a0 + 217b2ad commit ccc7db7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class Compiler extends Tapable {
const finalCallback = (err, stats) => {
this.running = false;

if (err) {
this.hooks.failed.call(err);
}

if (callback !== undefined) return callback(err, stats);
};

Expand Down
21 changes: 21 additions & 0 deletions test/Compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,25 @@ describe("Compiler", () => {
});
});
});
it("should call the failed-hook on error", done => {
const failedSpy = jest.fn();
const compiler = webpack({
bail: true,
context: __dirname,
mode: "production",
entry: "./missing",
output: {
path: "/",
filename: "bundle.js"
},
});
compiler.hooks.failed.tap('CompilerTest', failedSpy);
compiler.outputFileSystem = new MemoryFs();
compiler.run((err, stats) => {
expect(err).toBeTruthy();
expect(failedSpy).toHaveBeenCalledTimes(1);
expect(failedSpy).toHaveBeenCalledWith(err);
done();
});
});
});

0 comments on commit ccc7db7

Please sign in to comment.