From b3b384e59bac89830dc188611e527b341d062d28 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 6 Dec 2022 13:21:02 -0500 Subject: [PATCH] fix: don't use a symbol for runHook() This is not exposed to userland, so there is no need to put it behind a symbol. PR-URL: https://github.com/nodejs/node/pull/45792 Reviewed-By: Moshe Atlow Reviewed-By: Matteo Collina (cherry picked from commit 8302b0add01758713246117d3d0533cd212f160d) --- lib/internal/test_runner/test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 5a5c136..98e1993 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -1,4 +1,4 @@ -// https://github.com/nodejs/node/blob/f8ce9117b19702487eb600493d941f7876e00e01/lib/internal/test_runner/test.js +// https://github.com/nodejs/node/blob/8302b0add01758713246117d3d0533cd212f160d/lib/internal/test_runner/test.js 'use strict' @@ -80,7 +80,6 @@ const testNamePatterns = testNamePatternFlag?.length > 0 ) : null const kShouldAbort = Symbol('kShouldAbort') -const kRunHook = Symbol('kRunHook') const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']) const kUnwrapErrors = new SafeSet() .add(kTestCodeFailure).add(kHookFailure) @@ -464,7 +463,7 @@ class Test extends AsyncResource { return { ctx, args: [ctx] } } - async [kRunHook] (hook, args) { + async runHook (hook, args) { validateOneOf(hook, 'hook name', kHookNames) try { await ArrayPrototypeReduce(this.hooks[hook], async (prev, hook) => { @@ -495,13 +494,13 @@ class Test extends AsyncResource { const { args, ctx } = this.getRunArgs() const afterEach = runOnce(async () => { if (this.parent?.hooks.afterEach.length > 0) { - await this.parent[kRunHook]('afterEach', { args, ctx }) + await this.parent.runHook('afterEach', { args, ctx }) } }) try { if (this.parent?.hooks.beforeEach.length > 0) { - await this.parent[kRunHook]('beforeEach', { args, ctx }) + await this.parent.runHook('beforeEach', { args, ctx }) } const stopPromise = stopTest(this.timeout, this.signal) const runArgs = ArrayPrototypeSlice(args) @@ -751,9 +750,10 @@ class Suite extends Test { const hookArgs = this.getRunArgs() const afterEach = runOnce(async () => { if (this.parent?.hooks.afterEach.length > 0) { - await this.parent[kRunHook]('afterEach', hookArgs) + await this.parent.runHook('afterEach', hookArgs) } }) + try { this.parent.activeSubtests++ await this.buildSuite @@ -766,17 +766,17 @@ class Suite extends Test { } if (this.parent?.hooks.beforeEach.length > 0) { - await this.parent[kRunHook]('beforeEach', hookArgs) + await this.parent.runHook('beforeEach', hookArgs) } - await this[kRunHook]('before', hookArgs) + await this.runHook('before', hookArgs) const stopPromise = stopTest(this.timeout, this.signal) const subtests = this.skipped || this.error ? [] : this.subtests const promise = SafePromiseAll(subtests, (subtests) => subtests.start()) await SafePromiseRace([promise, stopPromise]) - await this[kRunHook]('after', hookArgs) + await this.runHook('after', hookArgs) await afterEach() this.pass()