File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -1078,13 +1078,15 @@ class Test extends AsyncResource {
10781078 ctx . plan ( this . expectedAssertions ) ;
10791079 }
10801080
1081+ const wasSkippedBeforeRun = this . skipped ;
1082+
10811083 const after = async ( ) => {
10821084 if ( this . hooks . after . length > 0 ) {
10831085 await this . runHook ( 'after' , hookArgs ) ;
10841086 }
10851087 } ;
10861088 const afterEach = runOnce ( async ( ) => {
1087- if ( this . parent ?. hooks . afterEach . length > 0 && ! this . skipped ) {
1089+ if ( this . parent ?. hooks . afterEach . length > 0 && ! wasSkippedBeforeRun ) {
10881090 await this . parent . runHook ( 'afterEach' , hookArgs ) ;
10891091 }
10901092 } , kRunOnceOptions ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const assert = require ( 'node:assert' ) ;
4+ const common = require ( '../common' ) ;
5+ const { beforeEach, afterEach, test } = require ( 'node:test' ) ;
6+
7+ let afterEachRuntimeSkip = 0 ;
8+ let afterEachTotal = 0 ;
9+
10+ beforeEach ( common . mustCall ( ( ) => { } , 2 ) ) ;
11+
12+ afterEach ( common . mustCall ( ( t ) => {
13+ afterEachTotal ++ ;
14+ if ( t . name === 'runtime skip' ) {
15+ afterEachRuntimeSkip ++ ;
16+ }
17+ } , 2 ) ) ;
18+
19+ test ( 'normal test' , ( t ) => {
20+ t . assert . ok ( true ) ;
21+ } ) ;
22+
23+ test ( 'runtime skip' , ( t ) => {
24+ t . skip ( 'skip after setup' ) ;
25+ } ) ;
26+
27+ test ( 'static skip' , { skip : true } , common . mustNotCall ( ) ) ;
28+
29+ process . on ( 'exit' , ( ) => {
30+ assert . strictEqual ( afterEachRuntimeSkip , 1 ) ;
31+ assert . strictEqual ( afterEachTotal , 2 ) ;
32+ } ) ;
You can’t perform that action at this time.
0 commit comments