From 0e8070d4f2eb48878112bad0574c60a5f7a35abe Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 6 Mar 2024 21:13:50 -0500 Subject: [PATCH] Revert "test_runner: do not invoke after hook when test is empty" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/51998 Reviewed-By: Matthew Aitken Reviewed-By: Richard Lau Reviewed-By: Moshe Atlow Reviewed-By: Matteo Collina Reviewed-By: Marco Ippolito Reviewed-By: Michaƫl Zasso --- 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'); - })); -});