Skip to content

Commit

Permalink
fix(vitest): failed to load custom environment from js/ts file (#4255)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
  • Loading branch information
Dunqing and sheremet-va authored Oct 6, 2023
1 parent dc1e97d commit da8d057
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 1,183 deletions.
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

0 comments on commit da8d057

Please sign in to comment.