Skip to content

Commit 25b0646

Browse files
test_runner: run afterEach on runtime skip
Signed-off-by: Igor <igorshevelenkov4@gmail.com>
1 parent abddfc9 commit 25b0646

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/internal/test_runner/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
});

0 commit comments

Comments
 (0)