Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: do not invoke after hook when test is empty #51389

Merged
merged 1 commit into from
Jan 8, 2024
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());
});

Loading