test_runner: do not invoke after hook when test is empty

PR-URL: https://github.com/nodejs/node/pull/51389
Fixes: https://github.com/nodejs/node/issues/51371
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Marco Ippolito authored and GitHub committed 2024-01-08 10:03:45 +00:00
1 parent a568aaaea6
commit a53fd95d36
2 files changed
+13 -1

No files matched your search

+3 -1
View File
@@ -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 });
}
};
@@ -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');
}));
});