Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vitest/src/node/cli/cli-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TestModule, TestSuite } from '../reporters/reported-tasks'
import type { TestSpecification } from '../spec'
import type { UserConfig, VitestEnvironment, VitestRunMode } from '../types/config'
import { mkdirSync, writeFileSync } from 'node:fs'
import { dirname, relative, resolve } from 'pathe'
import { dirname, isAbsolute, relative, resolve } from 'pathe'
import { CoverageProviderMap } from '../../utils/coverage'
import { createVitest } from '../create'
import { FilesNotFoundError, GitNotFoundError, IncludeTaskLocationDisabledError, LocationFilterFileNotFoundError, RangeLocationFilterProvidedError } from '../errors'
Expand Down Expand Up @@ -317,7 +317,7 @@ function getEnvPackageName(env: VitestEnvironment) {
if (env in envPackageNames) {
return (envPackageNames as any)[env]
}
if (env[0] === '.' || env[0] === '/') {
if (env[0] === '.' || isAbsolute(env)) {
return null
}
return `vitest-environment-${env}`
Expand Down
19 changes: 19 additions & 0 deletions test/cli/test/run-custom-env.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createRequire } from 'node:module'
import { expect, test } from 'vitest'

import { runVitest } from '../../test-utils'
Expand All @@ -17,3 +18,21 @@ test('correctly runs tests if custom env is a file', async () => {
expect(stderr).toBe('')
expect(exitCode).toBe(0)
})

test('correctly runs tests if custom env is an absolute path', async () => {
const require = createRequire(import.meta.url)

const { stderr, exitCode } = await runVitest({
root: './fixtures/custom-file-env',
config: false,
environment: require.resolve('vitest-environment-custom'),
environmentOptions: {
custom: {
option: 'custom-option',
},
},
})

expect(stderr).toBe('')
expect(exitCode).toBe(0)
})
Loading