Skip to content

Commit

Permalink
test_runner: 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: #45792
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Dec 13, 2022
1 parent 8a03684 commit d1bd779
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit d1bd779

Please sign in to comment.