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

Failed to load custom environment from JS file #4237

Closed
6 tasks done
paescuj opened this issue Oct 4, 2023 · 1 comment · Fixed by #4255
Closed
6 tasks done

Failed to load custom environment from JS file #4237

paescuj opened this issue Oct 4, 2023 · 1 comment · Fixed by #4255
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@paescuj
Copy link
Contributor

paescuj commented Oct 4, 2023

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:

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.6

Used Package Manager

pnpm

Validations

@sheremet-va sheremet-va added bug p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Oct 4, 2023
@sheremet-va
Copy link
Member

Looks like resolvePath fails here.

Also – at least with the package setup – it seems like the file is preprocessed again

Yes, the behaviour was reverted, but I forgot to update documentation it looks like. This was intended change.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants