File tree Expand file tree Collapse file tree 4 files changed +31
-17
lines changed
test/fixtures/test-runner/aborts Expand file tree Collapse file tree 4 files changed +31
-17
lines changed Original file line number Diff line number Diff line change @@ -586,21 +586,10 @@ class Test extends AsyncResource {
586586 return ;
587587 }
588588
589- // Do not run for hooks and root test as hooks instance are shared between tests suite so aborting them will
590- // abort cause them to not run for further tests.
591- if ( this . parent !== null ) {
592- this . #abortController. abort ( ) ;
593- }
594-
595589 await afterEach ( ) ;
596590 await after ( ) ;
597591 this . pass ( ) ;
598592 } catch ( err ) {
599- // Do not run for hooks and root test as hooks instance are shared between tests suite so aborting them will
600- // abort cause them to not run for further tests.
601- if ( this . parent !== null ) {
602- this . #abortController. abort ( ) ;
603- }
604593 try { await afterEach ( ) ; } catch { /* test is already failing, let's ignore the error */ }
605594 try { await after ( ) ; } catch { /* Ignore error. */ }
606595 if ( isTestFailureError ( err ) ) {
@@ -612,6 +601,12 @@ class Test extends AsyncResource {
612601 } else {
613602 this . fail ( new ERR_TEST_FAILURE ( err , kTestCodeFailure ) ) ;
614603 }
604+ } finally {
605+ // Do not run for hooks and root test as hooks instance are shared between tests suite so aborting them will
606+ // abort cause them to not run for further tests.
607+ if ( this . parent !== null ) {
608+ this . #abortController. abort ( ) ;
609+ }
615610 }
616611
617612 // Clean up the test. Then, try to report the results and execute any
Original file line number Diff line number Diff line change 11const { test, afterEach} = require ( 'node:test' ) ;
22const assert = require ( 'node:assert' ) ;
3+ const { waitForAbort } = require ( './wait-for-abort-helper' ) ;
34
45let testCount = 0 ;
56let signal ;
67
78afterEach ( ( ) => {
8- testCount ++ ;
9- assert . equal ( signal . aborted , true ) ;
9+ assert . equal ( signal . aborted , false ) ;
1010
11- console . log ( `abort called for test ${ testCount } ` )
11+ waitForAbort ( { testNumber : ++ testCount , signal } ) ;
1212} ) ;
1313
1414test ( "sync" , ( t ) => {
Original file line number Diff line number Diff line change 11const { test, afterEach} = require ( 'node:test' ) ;
22const assert = require ( 'node:assert' ) ;
3+ const { waitForAbort} = require ( "./wait-for-abort-helper" ) ;
34
45let testCount = 0 ;
56let signal ;
67
78afterEach ( ( ) => {
8- testCount ++ ;
9- assert . equal ( signal . aborted , true ) ;
9+ assert . equal ( signal . aborted , false ) ;
1010
11- console . log ( `abort called for test ${ testCount } ` )
11+ waitForAbort ( { testNumber : ++ testCount , signal } ) ;
1212} ) ;
1313
1414test ( "sync" , ( t ) => {
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ waitForAbort : function ( { testNumber, signal } ) {
3+ let retries = 0 ;
4+
5+ const interval = setInterval ( ( ) => {
6+ retries ++ ;
7+ if ( signal . aborted ) {
8+ console . log ( `abort called for test ${ testNumber } ` ) ;
9+ clearInterval ( interval ) ;
10+ return ;
11+ }
12+
13+ if ( retries > 100 ) {
14+ clearInterval ( interval ) ;
15+ throw new Error ( `abort was not called for test ${ testNumber } ` ) ;
16+ }
17+ } , 10 ) ;
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments