From 2ca9516001e925d8e5e17fe968d89ec0730b461a Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Tue, 9 Aug 2022 12:23:21 +0300 Subject: [PATCH] fix: implement `CallbackTestRunnerInterface` instead of extending `CallbackTestRunner` class (#134) --- lib/createJestRunner.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/createJestRunner.ts b/lib/createJestRunner.ts index 3bd7a21..00b957e 100644 --- a/lib/createJestRunner.ts +++ b/lib/createJestRunner.ts @@ -1,6 +1,7 @@ import type { TestResult } from '@jest/test-result'; -import { - CallbackTestRunner, +import type { + CallbackTestRunnerInterface, + Config, OnTestFailure, OnTestStart, OnTestSuccess, @@ -32,8 +33,14 @@ export default function createRunner< >( runPath: string, { getExtraOptions }: CreateRunnerOptions = {}, -): typeof CallbackTestRunner { - return class BaseTestRunner extends CallbackTestRunner { +) { + return class BaseTestRunner implements CallbackTestRunnerInterface { + #globalConfig: Config.GlobalConfig; + + constructor(globalConfig: Config.GlobalConfig) { + this.#globalConfig = globalConfig; + } + runTests( tests: Array, watcher: TestWatcher, @@ -84,7 +91,7 @@ export default function createRunner< const runner = require(runPath); const baseOptions = { config: test.context.config, - globalConfig: this._globalConfig, + globalConfig: this.#globalConfig, testPath: test.path, rawModuleMap: watcher.isWatchMode() ? test.context.moduleMap.getRawModuleMap() @@ -118,13 +125,13 @@ export default function createRunner< ): Promise { const worker = new Worker(runPath, { exposedMethods: ['default'], - numWorkers: this._globalConfig.maxWorkers, + numWorkers: this.#globalConfig.maxWorkers, forkOptions: { stdio: 'inherit' }, }) as JestWorkerFarm<{ default: (runTestOptions: RunTestOptions) => TestResult; }>; - const mutex = throat(this._globalConfig.maxWorkers); + const mutex = throat(this.#globalConfig.maxWorkers); const runTestInWorker = (test: Test) => mutex(() => { @@ -135,7 +142,7 @@ export default function createRunner< return onStart(test).then(() => { const runTestOptions: RunTestOptions = { config: test.context.config, - globalConfig: this._globalConfig, + globalConfig: this.#globalConfig, testPath: test.path, rawModuleMap: watcher.isWatchMode() ? test.context.moduleMap.getRawModuleMap()