-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
The documentation at https://vitest.dev/guide/environment.html#custom-environment states that since v0.34.0 a custom environment can be a valid JS file (instead of a vitest-environment-${name} package).
However, with a configuration like the following
export default defineConfig({
test: {
environment: './custom.js',
},
});it still tries to load the custom environment from a package:
MISSING DEP Can not find dependency 'vitest-environment-./custom.js'The resolve logic seems to differentiate correctly here:
vitest/packages/vitest/src/integrations/env/index.ts
Lines 55 to 57 in 22181f0
| const packageId = name[0] === '.' || name[0] === '/' | |
| ? resolve(root, name) | |
| : await resolvePath(`vitest-environment-${name}`, { url: [root] }) ?? resolve(root, name) |
So I'd guess there's an issue in the loader used at the next line:
| const pkg = await loader.executeId(normalize(packageId)) |
Also – at least with the package setup – it seems like the file is preprocessed again, despite the statement from v0.34.0:
Custom environment now should be processed before Vitest can consume it. It means that you cannot specify a path to a TS file or use import paths that should be processed by Vite.
For example, a setup like this works fine: https://github.com/vitest-dev/vitest/blob/main/test/env-custom/vitest-environment-custom/package.json
Related to #4196?
If this is indeed supported again and once this issue here has been addressed, could the documentation be updated to specify a path to a valid JS/TS file?
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-uefbmr
System Info
System:
OS: macOS 13.5.2
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 9.84 GB / 32.00 GB
Shell: 5.2.15 - /usr/local/bin/bash
Binaries:
Node: 18.18.0 - /usr/local/opt/node@18/bin/node
npm: 10.1.0 - /usr/local/bin/npm
pnpm: 8.8.0 - /usr/local/bin/pnpm
npmPackages:
vitest: 0.34.6 => 0.34.6Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.