Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4890d6b

Browse filesBrowse files
igor-shevelenkovaduh95
authored andcommitted
test_runner: run afterEach on runtime skip
Signed-off-by: Igor <igorshevelenkov4@gmail.com> PR-URL: #61525 Fixes: #61462 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent a32a598 commit 4890d6b
Copy full SHA for 4890d6b

2 files changed

+39-1Lines changed: 39 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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);
Collapse file
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.