File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1152,13 +1152,15 @@ class Test extends AsyncResource {
11521152 ctx . plan ( this . expectedAssertions ) ;
11531153 }
11541154
1155+ const wasSkippedBeforeRun = this . skipped ;
1156+
11551157 const after = async ( ) => {
11561158 if ( this . hooks . after . length > 0 ) {
11571159 await this . runHook ( 'after' , hookArgs ) ;
11581160 }
11591161 } ;
11601162 const afterEach = runOnce ( async ( ) => {
1161- if ( this . parent ?. hooks . afterEach . length > 0 && ! this . skipped ) {
1163+ if ( this . parent ?. hooks . afterEach . length > 0 && ! wasSkippedBeforeRun ) {
11621164 await this . parent . runHook ( 'afterEach' , hookArgs ) ;
11631165 }
11641166 } , kRunOnceOptions ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const assert = require ( 'node:assert' ) ;
5+ const { beforeEach, afterEach, test } = require ( 'node:test' ) ;
6+
7+ let beforeEachTotal = 0 ;
8+ let afterEachRuntimeSkip = 0 ;
9+ let afterEachTotal = 0 ;
10+
11+ beforeEach ( common . mustCall ( ( ) => {
12+ beforeEachTotal ++ ;
13+ } , 2 ) ) ;
14+
15+ afterEach ( common . mustCall ( ( t ) => {
16+ afterEachTotal ++ ;
17+ if ( t . name === 'runtime skip' ) {
18+ afterEachRuntimeSkip ++ ;
19+ }
20+ } , 2 ) ) ;
21+
22+ test ( 'normal test' , ( t ) => {
23+ t . assert . ok ( true ) ;
24+ } ) ;
25+
26+ test ( 'runtime skip' , ( t ) => {
27+ t . skip ( 'skip after setup' ) ;
28+ } ) ;
29+
30+ test ( 'static skip' , { skip : true } , common . mustNotCall ( ) ) ;
31+
32+ process . on ( 'exit' , ( ) => {
33+ assert . strictEqual ( beforeEachTotal , 2 ) ;
34+ assert . strictEqual ( afterEachRuntimeSkip , 1 ) ;
35+ assert . strictEqual ( afterEachTotal , 2 ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments