Skip to content

Commit

Permalink
fix(vitest): don't fail if the working directory starts with a small …
Browse files Browse the repository at this point in the history
…drive letter

Fixes vitest-dev#5772
Fixes vitest-dev#5798
Fixes vitest-dev#5251
  • Loading branch information
sheremet-va committed Oct 25, 2024
1 parent 169028f commit f07ebde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
16 changes: 0 additions & 16 deletions packages/vite-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ import { dirname, join, resolve } from 'pathe'

export const isWindows = process.platform === 'win32'

const drive = isWindows ? process.cwd()[0] : null
const driveOpposite = drive
? drive === drive.toUpperCase()
? drive.toLowerCase()
: drive.toUpperCase()
: null
const driveRegexp = drive ? new RegExp(`(?:^|/@fs/)${drive}(\:[\\/])`) : null
const driveOppositeRegext = driveOpposite
? new RegExp(`(?:^|/@fs/)${driveOpposite}(\:[\\/])`)
: null

export function slash(str: string) {
return str.replace(/\\/g, '/')
}
Expand All @@ -28,11 +17,6 @@ export function normalizeRequestId(id: string, base?: string): string {
id = `/${id.slice(base.length)}`
}

// keep drive the same as in process cwd
if (driveRegexp && !driveRegexp?.test(id) && driveOppositeRegext?.test(id)) {
id = id.replace(driveOppositeRegext, `${drive}$1`)
}

return id
.replace(/^\/@id\/__x00__/, '\0') // virtual modules start with `\0`
.replace(/^\/@id\//, '')
Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/node/cli/cac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ function normalizeCliOptions(argv: CliOptions): CliOptions {
async function start(mode: VitestRunMode, cliFilters: string[], options: CliOptions): Promise<void> {
try {
process.title = 'node (vitest)'
// pathe always normalizes the drive letter to be uppercase
// if user runs Vitest from c:/, the built-in ESM loader in tests
// will resolve a different Vitest instance than the one in vite-node
// we can either
// 1. normalize the CWD so it works in the CLI, but might break when API is used directly
// 2. ask "pathe" to not normalize the drive letter
// 2. don't use "pathe" when resolving paths
process.chdir(normalize(process.cwd()))
}
catch {}

Expand Down

0 comments on commit f07ebde

Please sign in to comment.