diff --git a/src/pure/ApiProcess.ts b/src/pure/ApiProcess.ts index 461b848f..7acb8b9b 100644 --- a/src/pure/ApiProcess.ts +++ b/src/pure/ApiProcess.ts @@ -72,7 +72,7 @@ export class ApiProcess { log.info('Start api process at port', port) log.info('[RUN]', `${this.vitest.cmd} ${this.vitest.args.join(' ')}`) - const cwd = sanitizeFilePath(this.workspace) + const cwd = sanitizeFilePath(this.workspace, false) log.info('[RUN.cwd]', cwd) const logs = [] as string[] diff --git a/src/pure/runner.ts b/src/pure/runner.ts index ca1e2550..a21e75e5 100644 --- a/src/pure/runner.ts +++ b/src/pure/runner.ts @@ -72,7 +72,7 @@ export class TestRunner { const command = vitestCommand.cmd const args = [ ...vitestCommand.args, - ...(testFile ? testFile.map(f => sanitizeFilePath(f)) : []), + ...(testFile ? testFile.map(f => sanitizeFilePath(f, true)) : []), ] as string[] if (updateSnapshot) args.push('--update') @@ -80,11 +80,11 @@ export class TestRunner { if (testNamePattern) args.push('-t', testNamePattern.replace(/[$^+?()[\]]/g, '\\$&')) - const workspacePath = sanitizeFilePath(this.workspacePath) + const workspacePath = sanitizeFilePath(this.workspacePath, false) const outputs: string[] = [] const env = { ...process.env, ...workspaceEnv } let testResultFiles = [] as File[] - const output = await runVitestWithApi({ cmd: sanitizeFilePath(command), args }, this.workspacePath, { + const output = await runVitestWithApi({ cmd: sanitizeFilePath(command, false), args }, this.workspacePath, { log: (line) => { log.info(`${filterColorFormatOutput(line.trimEnd())}\r\n`) outputs.push(filterColorFormatOutput(line)) diff --git a/src/pure/utils.ts b/src/pure/utils.ts index 6a9d56ef..a40666b3 100644 --- a/src/pure/utils.ts +++ b/src/pure/utils.ts @@ -17,13 +17,14 @@ export function getVitestPath(projectRoot: string): string | undefined { return if (existsSync(path.resolve(node_modules, 'vitest', 'vitest.mjs'))) - return sanitizeFilePath(path.resolve(node_modules, 'vitest', 'vitest.mjs')) + return sanitizeFilePath(path.resolve(node_modules, 'vitest', 'vitest.mjs'), false) const suffixes = ['.js', '', '.cmd'] for (const suffix of suffixes) { if (existsSync(path.resolve(node_modules, '.bin', `vitest${suffix}`))) { return sanitizeFilePath( path.resolve(node_modules, '.bin', `vitest${suffix}`), + false, ) } } @@ -62,7 +63,7 @@ export function getVitestCommand( return { cmd: 'node', args: [ - sanitizeFilePath(path.resolve(node_modules, 'vitest', 'vitest.mjs')), + sanitizeFilePath(path.resolve(node_modules, 'vitest', 'vitest.mjs'), false), ], } } @@ -124,14 +125,21 @@ export function isNodeAvailable( }) } -const capitalizeFirstLetter = (string: string) => - string.charAt(0).toUpperCase() + string.slice(1) +const removeDriveLetter = (string: string) => { + if (string.match(/^[a-zA-Z]:/)) + return string.slice(2) + return string +} const replaceDoubleSlashes = (string: string) => string.replace(/\\/g, '/') -export function sanitizeFilePath(path: string) { - if (isWindows) - return replaceDoubleSlashes(path) +export function sanitizeFilePath(path: string, isTestPattern: boolean) { + if (isWindows) { + if (isTestPattern) + return replaceDoubleSlashes(removeDriveLetter(path)) + else + return replaceDoubleSlashes(path) + } return path }