File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ class BundleAnalyzerPlugin {
6969 // Making analyzer logs to be after all webpack logs in the console
7070 setImmediate ( async ( ) => {
7171 try {
72- await Promise . all ( actions . map ( action => action ( ) ) ) ;
72+ await Promise . all ( actions . map ( ( action ) => action ( ) ) ) ;
7373 } finally {
7474 callback ( ) ;
7575 }
Original file line number Diff line number Diff line change 1+ "use strict" ;
2+
3+ const webpack = require ( "webpack" ) ;
4+ const BundleAnalyzerPlugin = require ( "../src/BundleAnalyzerPlugin" ) ;
5+
6+ describe ( "Issue #499" , ( ) => {
7+ it ( "should not cause WebpackLogger 'done hook' error when callback throws" , ( done ) => {
8+ expect . assertions ( 1 ) ;
9+
10+ const compiler = webpack ( {
11+ mode : "development" ,
12+ entry : __filename ,
13+ plugins : [ new BundleAnalyzerPlugin ( { analyzerMode : "disabled" } ) ] ,
14+ } ) ;
15+
16+ let webpackLoggerError = false ;
17+ const originalConsoleError = console . error ;
18+
19+ console . error = ( ...args ) => {
20+ const message = args . join ( " " ) ;
21+ if ( message . includes ( "No such label 'done hook'" ) ) {
22+ webpackLoggerError = true ;
23+ }
24+ originalConsoleError . apply ( console , args ) ;
25+ } ;
26+
27+ compiler . run ( ( ) => {
28+ try {
29+ throw new Error ( "Intentional test error" ) ;
30+ } catch {
31+ // Swallow expected error
32+ }
33+ } ) ;
34+
35+ setTimeout ( ( ) => {
36+ console . error = originalConsoleError ;
37+
38+ expect ( webpackLoggerError ) . toBe ( false ) ;
39+ done ( ) ;
40+ } , 1000 ) ;
41+ } ) ;
42+ } ) ;
Original file line number Diff line number Diff line change @@ -215,7 +215,7 @@ describe("Plugin", () => {
215215 expect ( generatedReportTitle ) . toBe ( reportTitleResult ) ;
216216 } ) ;
217217
218- it ( "should propagate an error in a function " , async ( ) => {
218+ it ( "should log an error when reportTitle throws " , async ( ) => {
219219 const reportTitleError = new Error ( "test" ) ;
220220 const config = makeWebpackConfig ( {
221221 analyzerOpts : {
@@ -225,14 +225,17 @@ describe("Plugin", () => {
225225 } ,
226226 } ) ;
227227
228- let error = null ;
229- try {
230- await webpackCompile ( config , "4.44.2" ) ;
231- } catch ( err ) {
232- error = err ;
233- }
228+ const errorSpy = jest
229+ . spyOn ( console , "error" )
230+ . mockImplementation ( ( ) => { } ) ;
231+
232+ await webpackCompile ( config , "4.44.2" ) ;
234233
235- expect ( error ) . toBe ( reportTitleError ) ;
234+ expect ( errorSpy ) . toHaveBeenCalledWith (
235+ expect . stringContaining ( "action failed: test" ) ,
236+ ) ;
237+
238+ errorSpy . mockRestore ( ) ;
236239 } ) ;
237240 } ) ;
238241
@@ -257,8 +260,8 @@ describe("Plugin", () => {
257260 } ) ;
258261 await webpackCompile ( config , "4.44.2" ) ;
259262 await expectValidReport ( {
260- gzipSize : undefined ,
261263 parsedSize : 1317 ,
264+ gzipSize : undefined ,
262265 brotliSize : 295 ,
263266 } ) ;
264267 } ) ;
You can’t perform that action at this time.
0 commit comments