From d1bd7796ad474b54d76f5627a4d238ada81deff8 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 6 Dec 2022 13:21:02 -0500 Subject: [PATCH] test_runner: 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 --- lib/internal/test_runner/test.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index c56c03c0725586..96c86ab3ed6d08 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -75,7 +75,6 @@ const testNamePatterns = testNamePatternFlag?.length > 0 ? (re) => convertStringToRegExp(re, '--test-name-pattern') ) : null; const kShouldAbort = Symbol('kShouldAbort'); -const kRunHook = Symbol('kRunHook'); const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']); const kUnwrapErrors = new SafeSet() .add(kTestCodeFailure).add(kHookFailure) @@ -476,7 +475,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) => { @@ -507,13 +506,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); @@ -761,9 +760,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; @@ -775,19 +775,18 @@ class Suite extends Test { return; } - 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();