Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ class Test extends AsyncResource {

const { args, ctx } = this.getRunArgs();
const after = async () => {
if (this.hooks.after.length > 0) {
// If its a root test then check for global after hook else check for parent after hook
const check = this.parent ? this.parent.hooks.after.length > 0 : this.hooks.after.length > 0;
if (check) {
await this.runHook('after', { __proto__: null, args, ctx });
}
};
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-runner-skip-after-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';
// Refs: https://github.com/nodejs/node/issues/51371
const common = require('../common');
const { test } = require('node:test');

test('test', async (t) => {
t.after(common.mustNotCall(() => {
t.fail('should not run');
}));
});
Comment on lines +6 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
test('test', async (t) => {
t.after(common.mustNotCall(() => {
t.fail('should not run');
}));
});
test('test', (t) => {
t.after(common.mustNotCall());
});