Skip to content

Commit 8adf325

Browse files
authored
fix(vscode-extension): import rstest error on windows (#693)
1 parent 5ab28b7 commit 8adf325

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/vscode/src/worker/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import { pathToFileURL } from 'node:url';
12
import { WebSocket } from 'ws';
23
import type { WorkerInitData, WorkerRunTestData } from '../types';
34
import { logger } from './logger';
45
import { VscodeReporter } from './reporter';
56

67
type CommonOptions = Parameters<typeof import('@rstest/core').initCli>[0];
78

9+
// fix ESM import path issue on windows
10+
// Only URLs with a scheme in: file, data, and node are supported by the default ESM loader.
11+
const normalizeImportPath = (path: string) => {
12+
return pathToFileURL(path).toString();
13+
};
14+
815
class Worker {
916
private ws: WebSocket;
1017
public rstestPath!: string;
@@ -51,7 +58,7 @@ class Worker {
5158

5259
public async createRstest(data: WorkerRunTestData) {
5360
const rstestModule = (await import(
54-
this.rstestPath
61+
normalizeImportPath(this.rstestPath)
5562
)) as typeof import('@rstest/core');
5663
logger.debug('Loaded Rstest module');
5764
const { createRstest, initCli } = rstestModule;

0 commit comments

Comments
 (0)