From 324b85f5dd0d8e377ff09f46a6e98d578c7dc494 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 14 Sep 2022 12:44:54 +0200 Subject: [PATCH] convert to URL for import --- lib/createJestRunner.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/createJestRunner.ts b/lib/createJestRunner.ts index 301e8db..e15e405 100644 --- a/lib/createJestRunner.ts +++ b/lib/createJestRunner.ts @@ -1,3 +1,5 @@ +import * as path from 'path'; +import * as url from 'url'; import type { TestResult } from '@jest/test-result'; import type { CallbackTestRunnerInterface, @@ -36,6 +38,15 @@ export default function createRunner< runPath: string, { getExtraOptions }: CreateRunnerOptions = {}, ) { + if (!runPath.startsWith('file')) { + if (!path.isAbsolute(runPath)) { + throw new Error(`Path must be absolute - got ${runPath}`); + } + + // eslint-disable-next-line no-param-reassign + runPath = url.pathToFileURL(runPath).href; + } + return class BaseTestRunner implements CallbackTestRunnerInterface { #globalConfig: Config.GlobalConfig; @@ -121,7 +132,7 @@ export default function createRunner< onFailure: OnTestFailure, options: TestRunnerOptions, ): Promise { - const worker = new Worker(runPath, { + const worker = new Worker(url.fileURLToPath(runPath), { exposedMethods: ['default'], numWorkers: this.#globalConfig.maxWorkers, forkOptions: { stdio: 'inherit' },