Skip to content

Commit

Permalink
fix: implement CallbackTestRunnerInterface instead of extending `Ca…
Browse files Browse the repository at this point in the history
…llbackTestRunner` class (#134)
  • Loading branch information
mrazauskas authored Aug 9, 2022
1 parent 445b564 commit 2ca9516
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/createJestRunner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TestResult } from '@jest/test-result';
import {
CallbackTestRunner,
import type {
CallbackTestRunnerInterface,
Config,
OnTestFailure,
OnTestStart,
OnTestSuccess,
Expand Down Expand Up @@ -32,8 +33,14 @@ export default function createRunner<
>(
runPath: string,
{ getExtraOptions }: CreateRunnerOptions<ExtraOptions> = {},
): 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<Test>,
watcher: TestWatcher,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -118,13 +125,13 @@ export default function createRunner<
): Promise<void> {
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(() => {
Expand All @@ -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()
Expand Down

0 comments on commit 2ca9516

Please sign in to comment.