8000 Merge pull request #8401 from shahkashani/fix-for-issue-8398 · tyroprogrammer/webpack@ccc7db7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ccc7db7

Browse files
authored
Merge pull request webpack#8401 from shahkashani/fix-for-issue-8398
Fix for webpack#8398 - call failed-hook on compilation errors
2 parents 2e3e2a0 + 217b2ad commit ccc7db7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Compiler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ class Compiler extends Tapable {
207207
const finalCallback = (err, stats) => {
208208
this.running = false;
209209

210+
if (err) {
211+
this.hooks.failed.call(err);
212+
}
213+
210214
if (callback !== undefined) return callback(err, stats);
211215
};
212216

test/Compiler.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,25 @@ describe("Compiler", () => {
493493
});
494494
});
495495
});
496+
it("should call the failed-hook on error", done => {
497+
const failedSpy = jest.fn();
498+
const compiler = webpack({
499+
bail: true,
500+
context: __dirname,
501+
mode: "production",
502+
entry: "./missing",
503+
output: {
504+
path: "/",
505+
filename: "bundle.js"
506+
},
507+
});
508+
compiler.hooks.failed.tap('CompilerTest', failedSpy);
509+
compiler.outputFileSystem = new MemoryFs();
510+
compiler.run((err, stats) => {
511+
expect(err).toBeTruthy();
512+
expect(failedSpy).toHaveBeenCalledTimes(1);
513+
expect(failedSpy).toHaveBeenCalledWith(err);
514+
done();
515+
});
516+
});
496517
});

0 commit comments

Comments
 (0)
0