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 e0789fb

Browse filesBrowse files
marco-ippolitotargos
authored andcommitted
test_runner: do not invoke after hook when test is empty
PR-URL: #51389 Fixes: #51371 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 76582e4 commit e0789fb
Copy full SHA for e0789fb

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
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
@@ -587,7 +587,9 @@ class Test extends AsyncResource {
587587

588588
const { args, ctx } = this.getRunArgs();
589589
const after = async () => {
590-
if (this.hooks.after.length > 0) {
590+
// If its a root test then check for global after hook else check for parent after hook
591+
const check = this.parent ? this.parent.hooks.after.length > 0 : this.hooks.after.length > 0;
592+
if (check) {
591593
await this.runHook('after', { __proto__: null, args, ctx });
592594
}
593595
};
Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
// Refs: https://github.com/nodejs/node/issues/51371
3+
const common = require('../common');
4+
const { test } = require('node:test');
5+
6+
test('test', async (t) => {
7+
t.after(common.mustNotCall(() => {
8+
t.fail('should not run');
9+
}));
10+
});

0 commit comments

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