Skip to content

Commit

Permalink
test_runner: do not invoke after hook when test is empty
Browse files Browse the repository at this point in the history
PR-URL: #51389
Fixes: #51371
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
  • Loading branch information
marco-ippolito authored and targos committed Feb 15, 2024
1 parent 76582e4 commit e0789fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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');
}));
});

0 comments on commit e0789fb

Please sign in to comment.