Skip to content

Commit da8d057

Browse files
Dunqingsheremet-va
andauthored
fix(vitest): failed to load custom environment from js/ts file (#4255)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
1 parent dc1e97d commit da8d057

File tree

7 files changed

+337
-1183
lines changed

7 files changed

+337
-1183
lines changed

docs/guide/environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Or you can also set [`environmentMatchGlobs`](https://vitest.dev/config/#environ
2727

2828
## Custom Environment
2929

30-
Starting from 0.23.0, you can create your own package to extend Vitest environment. To do so, create package with the name `vitest-environment-${name}` or specify a path to a valid JS file (supported since 0.34.0). That package should export an object with the shape of `Environment`:
30+
Starting from 0.23.0, you can create your own package to extend Vitest environment. To do so, create package with the name `vitest-environment-${name}` or specify a path to a valid JS/TS file (supported since 0.34.0). That package should export an object with the shape of `Environment`:
3131

3232
```ts
3333
import type { Environment } from 'vitest'

packages/vitest/src/integrations/env/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export function getEnvPackageName(env: VitestEnvironment) {
3333
return null
3434
if (env in envPackageNames)
3535
return (envPackageNames as any)[env]
36+
if (env[0] === '.' || env[0] === '/')
37+
return null
3638
return `vitest-environment-${env}`
3739
}
3840

0 commit comments

Comments
 (0)