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: nodejs#51389
Fixes: nodejs#51371
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
marco-ippolito authored Jan 8, 2024
1 parent a568aaa commit a53fd95
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 a53fd95

Please sign in to comment.