Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vitest): failed to load custom environment from js/ts file #4255

Merged
merged 4 commits into from
Oct 6, 2023
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
2 changes: 1 addition & 1 deletion docs/guide/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Or you can also set [`environmentMatchGlobs`](https://vitest.dev/config/#environ

## Custom Environment

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`:
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`:

```ts
import type { Environment } from 'vitest'
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/integrations/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function getEnvPackageName(env: VitestEnvironment) {
return null
if (env in envPackageNames)
return (envPackageNames as any)[env]
if (env[0] === '.' || env[0] === '/')
return null
return `vitest-environment-${env}`
}

Expand Down
Loading
Loading