@@ -319,6 +319,22 @@ const describeCases = (config) => {
319319 setTimeout ( done , 200 ) ;
320320 } ;
321321
322+ /**
323+ * Closes the compiler before reporting a failed build. Left open, its
324+ * filesystem cache still stores the pack once idle, after the test is
325+ * over and at the same time as the next compiler on the same cache
326+ * directory, and one store then renames a file away from the other.
327+ * @param {import("../../").Compiler } compiler compiler that failed
328+ * @param {Error } err the fatal error
329+ * @param {(err?: Error) => void } done done callback
330+ */
331+ const closeAfterFatalError = ( compiler , err , done ) => {
332+ compiler . close ( ( closeErr ) => {
333+ if ( closeErr ) return done ( closeErr ) ;
334+ handleFatalError ( err , done ) ;
335+ } ) ;
336+ } ;
337+
322338 /**
323339 * Runs the compiler, reporting a synchronous throw from a hook
324340 * (e.g. a `compilation` tap) to the callback like a failed run.
@@ -350,7 +366,7 @@ const describeCases = (config) => {
350366
351367 runCompiler ( compiler , ( err ) => {
352368 deprecationTracker ( ) ;
353- if ( err ) return handleFatalError ( err , done ) ;
369+ if ( err ) return closeAfterFatalError ( compiler , err , done ) ;
354370 // Check after close: the disk cache is stored during close,
355371 // so store failures (warnings) only surface afterwards.
356372 compiler . close ( ( closeErr ) => {
@@ -401,7 +417,11 @@ const describeCases = (config) => {
401417 runCompiler ( compiler , ( err , stats ) => {
402418 deprecationTracker ( ) ;
403419 if ( err ) {
404- return handleFatalError ( /** @type {Error } */ ( err ) , done ) ;
420+ return closeAfterFatalError (
421+ compiler ,
422+ /** @type {Error } */ ( err ) ,
423+ done
424+ ) ;
405425 }
406426 const { modules, children, errorsCount } =
407427 /** @type {import("../../").Stats } */ ( stats ) . toJson ( {
@@ -690,7 +710,11 @@ const describeCases = (config) => {
690710
691711 compiler . run ( ( err ) => {
692712 if ( err ) {
693- return handleFatalError ( /** @type {Error } */ ( err ) , done ) ;
713+ return closeAfterFatalError (
714+ compiler ,
715+ /** @type {Error } */ ( err ) ,
716+ done
717+ ) ;
694718 }
695719 compiler . run ( ( error , stats ) => {
696720 compiler . close ( ( err ) => {
0 commit comments