From c39a545bd96873873f2f5f4aff299194438964b8 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 6 Mar 2024 21:13:50 -0500 Subject: [PATCH 1/2] Revert "test_runner: do not invoke after hook when test is empty" This reverts commit a53fd95d363f1897549a074a53d29590d58f2dc7. This caused a regression because the original issue this commit was attempting to fix is not a bug. The after() hook should always run. Fixes: https://github.com/nodejs/node/issues/51997 --- lib/internal/test_runner/test.js | 4 +--- test/parallel/test-runner-skip-after-hook.js | 10 ---------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 test/parallel/test-runner-skip-after-hook.js diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index e39c61c3390dd7..57b58d6320ab42 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -617,9 +617,7 @@ class Test extends AsyncResource { const { args, ctx } = this.getRunArgs(); const after = async () => { - // 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) { + if (this.hooks.after.length > 0) { await this.runHook('after', { __proto__: null, args, ctx }); } }; diff --git a/test/parallel/test-runner-skip-after-hook.js b/test/parallel/test-runner-skip-after-hook.js deleted file mode 100644 index d8175135b02f0d..00000000000000 --- a/test/parallel/test-runner-skip-after-hook.js +++ /dev/null @@ -1,10 +0,0 @@ -'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'); - })); -}); From cfccb99601219ff012710186ca89d20c72d6b6cc Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 6 Mar 2024 21:25:54 -0500 Subject: [PATCH 2/2] test: add regression test for test_runner after hook Refs: https://github.com/nodejs/node/issues/51997 --- test/parallel/test-runner-subtest-after-hook.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/parallel/test-runner-subtest-after-hook.js diff --git a/test/parallel/test-runner-subtest-after-hook.js b/test/parallel/test-runner-subtest-after-hook.js new file mode 100644 index 00000000000000..f288abee243de2 --- /dev/null +++ b/test/parallel/test-runner-subtest-after-hook.js @@ -0,0 +1,12 @@ +'use strict'; +const common = require('../common'); +const { test } = require('node:test'); + +// Regression test for https://github.com/nodejs/node/issues/51997 +test('after hook should be called with no subtests', (t) => { + const timer = setTimeout(common.mustNotCall(), 2 ** 30); + + t.after(common.mustCall(() => { + clearTimeout(timer); + })); +});