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 {
586
586
return ;
587
587
}
588
588
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
-
595
589
await afterEach ( ) ;
596
590
await after ( ) ;
597
591
this . pass ( ) ;
598
592
} 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
- }
604
593
try { await afterEach ( ) ; } catch { /* test is already failing, let's ignore the error */ }
605
594
try { await after ( ) ; } catch { /* Ignore error. */ }
606
595
if ( isTestFailureError ( err ) ) {
@@ -612,6 +601,12 @@ class Test extends AsyncResource {
612
601
} else {
613
602
this . fail ( new ERR_TEST_FAILURE ( err , kTestCodeFailure ) ) ;
614
603
}
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
+ }
615
610
}
616
611
617
612
// Clean up the test. Then, try to report the results and execute any
Original file line number Diff line number Diff line change 1
1
const { test, afterEach} = require ( 'node:test' ) ;
2
2
const assert = require ( 'node:assert' ) ;
3
+ const { waitForAbort } = require ( './wait-for-abort-helper' ) ;
3
4
4
5
let testCount = 0 ;
5
6
let signal ;
6
7
7
8
afterEach ( ( ) => {
8
- testCount ++ ;
9
- assert . equal ( signal . aborted , true ) ;
9
+ assert . equal ( signal . aborted , false ) ;
10
10
11
- console . log ( `abort called for test ${ testCount } ` )
11
+ waitForAbort ( { testNumber : ++ testCount , signal } ) ;
12
12
} ) ;
13
13
14
14
test ( "sync" , ( t ) => {
Original file line number Diff line number Diff line change 1
1
const { test, afterEach} = require ( 'node:test' ) ;
2
2
const assert = require ( 'node:assert' ) ;
3
+ const { waitForAbort} = require ( "./wait-for-abort-helper" ) ;
3
4
4
5
let testCount = 0 ;
5
6
let signal ;
6
7
7
8
afterEach ( ( ) => {
8
- testCount ++ ;
9
- assert . equal ( signal . aborted , true ) ;
9
+ assert . equal ( signal . aborted , false ) ;
10
10
11
- console . log ( `abort called for test ${ testCount } ` )
11
+ waitForAbort ( { testNumber : ++ testCount , signal } ) ;
12
12
} ) ;
13
13
14
14
test ( "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