@@ -28,6 +28,7 @@ const {
2828 codes : {
2929 ERR_INVALID_ARG_TYPE ,
3030 ERR_TEST_FAILURE ,
31+ ERR_TEST_BAILOUT ,
3132 } ,
3233 AbortError,
3334} = require ( 'internal/errors' ) ;
@@ -71,8 +72,9 @@ const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']);
7172const kUnwrapErrors = new SafeSet ( )
7273 . add ( kTestCodeFailure ) . add ( kHookFailure )
7374 . add ( 'uncaughtException' ) . add ( 'unhandledRejection' ) ;
74- const { testNamePatterns, testOnlyFlag } = parseCommandLine ( ) ;
75+ const { testNamePatterns, testOnlyFlag, bail } = parseCommandLine ( ) ;
7576let kResistStopPropagation ;
77+ let bailedOut = false ;
7678
7779function stopTest ( timeout , signal ) {
7880 if ( timeout === kDefaultTimeout ) {
@@ -421,11 +423,13 @@ class Test extends AsyncResource {
421423 return ;
422424 }
423425
426+ const unknownError = bailedOut ? new ERR_TEST_BAILOUT ( 'test bailed out' ) : new ERR_TEST_FAILURE (
427+ 'test did not finish before its parent and was cancelled' ,
428+ kCancelledByParent ,
429+ ) ;
430+
424431 this . fail ( error ||
425- new ERR_TEST_FAILURE (
426- 'test did not finish before its parent and was cancelled' ,
427- kCancelledByParent ,
428- ) ,
432+ unknownError ,
429433 ) ;
430434 this . startTime = this . startTime || this . endTime ; // If a test was canceled before it was started, e.g inside a hook
431435 this . cancelled = true ;
@@ -444,6 +448,7 @@ class Test extends AsyncResource {
444448 }
445449
446450 fail ( err ) {
451+ bailedOut = bail ;
447452 if ( this . error !== null ) {
448453 return ;
449454 }
@@ -526,6 +531,10 @@ class Test extends AsyncResource {
526531 }
527532
528533 async run ( pendingSubtestsError ) {
534+ if ( bailedOut ) {
535+ return ;
536+ }
537+
529538 if ( this . parent !== null ) {
530539 this . parent . activeSubtests ++ ;
531540 }
0 commit comments