GeezerVison is showing github.com — Fix for #8398 - call failed-hook on compilation errors · webpack/webpack@217b2ad
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/Compiler.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -207,6 +207,10 @@ class Compiler extends Tapable { |
207 | 207 | const finalCallback = (err, stats) => { |
208 | 208 | this.running = false; |
209 | 209 |
|
| 210 | + if (err) { |
| 211 | + this.hooks.failed.call(err); |
| 212 | + } |
| 213 | + |
210 | 214 | if (callback !== undefined) return callback(err, stats); |
211 | 215 | }; |
212 | 216 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/Compiler.test.js +21Lines changed: 21 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -493,4 +493,25 @@ describe("Compiler", () => { |
493 | 493 | }); |
494 | 494 | }); |
495 | 495 | }); |
| 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 | + }); |
496 | 517 | }); |