Skip to content

Commit 2ca9516

Browse files
authored
fix: implement CallbackTestRunnerInterface instead of extending CallbackTestRunner class (#134)
1 parent 445b564 commit 2ca9516

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/createJestRunner.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { TestResult } from '@jest/test-result';
2-
import {
3-
CallbackTestRunner,
2+
import type {
3+
CallbackTestRunnerInterface,
4+
Config,
45
OnTestFailure,
56
OnTestStart,
67
OnTestSuccess,
@@ -32,8 +33,14 @@ export default function createRunner<
3233
>(
3334
runPath: string,
3435
{ getExtraOptions }: CreateRunnerOptions<ExtraOptions> = {},
35-
): typeof CallbackTestRunner {
36-
return class BaseTestRunner extends CallbackTestRunner {
36+
) {
37+
return class BaseTestRunner implements CallbackTestRunnerInterface {
38+
#globalConfig: Config.GlobalConfig;
39+
40+
constructor(globalConfig: Config.GlobalConfig) {
41+
this.#globalConfig = globalConfig;
42+
}
43+
3744
runTests(
3845
tests: Array<Test>,
3946
watcher: TestWatcher,
@@ -84,7 +91,7 @@ export default function createRunner<
8491
const runner = require(runPath);
8592
const baseOptions = {
8693
config: test.context.config,
87-
globalConfig: this._globalConfig,
94+
globalConfig: this.#globalConfig,
8895
testPath: test.path,
8996
rawModuleMap: watcher.isWatchMode()
9097
? test.context.moduleMap.getRawModuleMap()
@@ -118,13 +125,13 @@ export default function createRunner<
118125
): Promise<void> {
119126
const worker = new Worker(runPath, {
120127
exposedMethods: ['default'],
121-
numWorkers: this._globalConfig.maxWorkers,
128+
numWorkers: this.#globalConfig.maxWorkers,
122129
forkOptions: { stdio: 'inherit' },
123130
}) as JestWorkerFarm<{
124131
default: (runTestOptions: RunTestOptions) => TestResult;
125132
}>;
126133

127-
const mutex = throat(this._globalConfig.maxWorkers);
134+
const mutex = throat(this.#globalConfig.maxWorkers);
128135

129136
const runTestInWorker = (test: Test) =>
130137
mutex(() => {
@@ -135,7 +142,7 @@ export default function createRunner<
135142
return onStart(test).then(() => {
136143
const runTestOptions: RunTestOptions = {
137144
config: test.context.config,
138-
globalConfig: this._globalConfig,
145+
globalConfig: this.#globalConfig,
139146
testPath: test.path,
140147
rawModuleMap: watcher.isWatchMode()
141148
? test.context.moduleMap.getRawModuleMap()

0 commit comments

Comments
 (0)