Skip to content

Commit 85dc019

Browse files
authored
fix(cli): use absolute path environment on Windows (#8105)
1 parent 27df68a commit 85dc019

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/vitest/src/node/cli/cli-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { TestModule, TestSuite } from '../reporters/reported-tasks'
55
import type { TestSpecification } from '../spec'
66
import type { UserConfig, VitestEnvironment, VitestRunMode } from '../types/config'
77
import { mkdirSync, writeFileSync } from 'node:fs'
8-
import { dirname, relative, resolve } from 'pathe'
8+
import { dirname, isAbsolute, relative, resolve } from 'pathe'
99
import { CoverageProviderMap } from '../../utils/coverage'
1010
import { createVitest } from '../create'
1111
import { FilesNotFoundError, GitNotFoundError, IncludeTaskLocationDisabledError, LocationFilterFileNotFoundError, RangeLocationFilterProvidedError } from '../errors'
@@ -317,7 +317,7 @@ function getEnvPackageName(env: VitestEnvironment) {
317317
if (env in envPackageNames) {
318318
return (envPackageNames as any)[env]
319319
}
320-
if (env[0] === '.' || env[0] === '/') {
320+
if (env[0] === '.' || isAbsolute(env)) {
321321
return null
322322
}
323323
return `vitest-environment-${env}`

test/cli/test/run-custom-env.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createRequire } from 'node:module'
12
import { expect, test } from 'vitest'
23

34
import { runVitest } from '../../test-utils'
@@ -17,3 +18,21 @@ test('correctly runs tests if custom env is a file', async () => {
1718
expect(stderr).toBe('')
1819
expect(exitCode).toBe(0)
1920
})
21+
22+
test('correctly runs tests if custom env is an absolute path', async () => {
23+
const require = createRequire(import.meta.url)
24+
25+
const { stderr, exitCode } = await runVitest({
26+
root: './fixtures/custom-file-env',
27+
config: false,
28+
environment: require.resolve('vitest-environment-custom'),
29+
environmentOptions: {
30+
custom: {
31+
option: 'custom-option',
32+
},
33+
},
34+
})
35+
36+
expect(stderr).toBe('')
37+
expect(exitCode).toBe(0)
38+
})

0 commit comments

Comments
 (0)