-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Error when using process.env.NODE_ENV with jsdom and @vitest/coverage-istanbul #3860
Comments
Istanbul instrumented code contains the source map where function cov_zu6h2qi9v() {
var coverageData = {
path: "/x/vitest/test/coverage-test/src/process-env.ts",
branchMap: { },
inputSourceMap: {
sourcesContent: ["export function getNodeEnv() {\n return process.env.NODE_ENV\n}\n"],
// ...
},
}
}
cov_zu6h2qi9v();
export function getNodeEnv() {
cov_zu6h2qi9v().f[0]++;
cov_zu6h2qi9v().s[0]++;
return "test";
} When inputSourceMap: {
- sourcesContent: ["export function getNodeEnv() {\n return process.env.NODE_ENV\n}\n"],
+ sourcesContent: ["export function getNodeEnv() {\n return "test"\n}\n"], |
This bug was introduced by #3491. |
Yes, |
As the |
meet the same problem when i upgrade from |
This isn't a proper fix, but the best solution I've found to resolve this issue right now is to add all your |
Updating Vitest to |
Describe the bug
When running
vitest
with coverage@vitest/coverage-istanbul
andjsdom
If the code is using the
process.env.NODE_ENV
, it will throw this error.In this error, you can see that the double quote of the
process.env.NODE_ENV
is not escaped.This error is gone after we remove the
jsdom
from the test environment.I try it with
v0.33
and there's no error.Reproduction
here's the minimal reproduction https://github.com/devpeerapong/vitest-034-jsdom-coverage-bug
vitest
,jsdom
,@vitest/coverage-istanbul
vitest.config.test
with this configurationindex.ts
indext.test.ts
vitest --coverage
. You will see the error.*If you comment out the
environment: "jsdom"
invitest.config.ts
or downgradevitest
tov0.33
, it will work.System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: