Skip to content

Commit

Permalink
fix: don't use a symbol for runHook()
Browse files Browse the repository at this point in the history
This is not exposed to userland, so there is no need to put it
behind a symbol.

PR-URL: nodejs/node#45792
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
(cherry picked from commit 8302b0add01758713246117d3d0533cd212f160d)
  • Loading branch information
cjihrig authored and MoLow committed Feb 2, 2023
1 parent b942f93 commit b3b384e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit b3b384e

Please sign in to comment.