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

V8 Coverage fails #5532

Closed
6 tasks done
digitalkaoz opened this issue Apr 13, 2024 · 9 comments · Fixed by #5549
Closed
6 tasks done

V8 Coverage fails #5532

digitalkaoz opened this issue Apr 13, 2024 · 9 comments · Fixed by #5549
Labels
feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@digitalkaoz
Copy link

digitalkaoz commented Apr 13, 2024

Describe the bug

❯ pnpm test:coverage

> app@0.0.0 test:coverage /path/to/app
> vitest run --coverage src/


 RUN  v1.5.0 /path/to/app
      Coverage enabled with v8

 Test Files  35 passed (35)
      Tests  420 passed | 3 skipped (423)
   Start at  10:27:11
   Duration  5.02s (transform 2.91s, setup 21.06s, collect 12.65s, tests 1.29s, environment 4.48s, prepare 2.21s)


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: requires Node.js >=10.12.0
 ❯ node_modules/.pnpm/@vitest+coverage-v8@1.5.0_vitest@1.5.0/node_modules/@vitest/coverage-v8/dist/provider.js:1803:21
 ❯ ModuleJob.run node:internal/modules/esm/module_job:222:25
 ❯ ModuleLoader.import node:internal/modules/esm/loader:323:24
 ❯ Object.getProvider node_modules/.pnpm/@vitest+coverage-v8@1.5.0_vitest@1.5.0/node_modules/@vitest/coverage-v8/dist/index.js:49:36
 ❯ Vitest.initCoverageProvider node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7_@vitest+ui@1.5.0_happy-dom@14.7.1_less@4.2.0/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:11651:29
 ❯ Vitest.start node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7_@vitest+ui@1.5.0_happy-dom@14.7.1_less@4.2.0/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:11665:7
 ❯ startVitest node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7_@vitest+ui@1.5.0_happy-dom@14.7.1_less@4.2.0/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:18863:5
 ❯ start node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7_@vitest+ui@1.5.0_happy-dom@14.7.1_less@4.2.0/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:19645:17
 ❯ CAC.run node_modules/.pnpm/vitest@1.5.0_@types+node@20.12.7_@vitest+ui@1.5.0_happy-dom@14.7.1_less@4.2.0/node_modules/vitest/dist/vendor/cac.qnW6GNL2.js:19626:3




 ELIFECYCLE  Command failed with exit code 1.

as you can see the tests are fine.

Reproduction

coverage is working perfectly fine with istanbul

from @ejexxeffer : https://stackblitz.com/~/github.com/ejexxeffer/datepickertest

System Info

environment (also fails in CI):

❯ pnpm --version
8.15.5
❯ node --version
v21.7.2
❯ vite --version
vite/5.2.8 darwin-arm64 node-v21.7.2

versions:

{
  "name": "app",
  "version": "0.0.0",
  "type": "module",
  "dependencies": {
    "vue": "^3.4.21",
    "vue-i18n": "^9.12.0",
    "vue-router": "^4.3.0",
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.0.4",
    "@vitest/coverage-v8": "^1.5.0",
    "@vitest/ui": "^1.5.0",
    "@vue/test-utils": "^2.4.5",
    "@vue/tsconfig": "^0.5.1",
    "happy-dom": "^14.7.1",
    "typescript": "^5.4.5",
    "vite": "^5.2.8",
    "vitest": "^1.5.0",
    "vue-tsc": "^2.0.13"
  },
  "engines": {
    "node": ">=20",
    "pnpm": ">=8.6"
  }
}

Used Package Manager

pnpm

Validations

Copy link

Hello @digitalkaoz. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@AriPerkkio
Copy link
Member

Without reproduction setup it's difficult to say what's going on here. Are your tests mocking fs?

https://github.com/istanbuljs/v8-to-istanbul/blob/fcc2e35891f9034ba5d283477e6da15336cb7372/lib/v8-to-istanbul.js#L11-L18

@digitalkaoz
Copy link
Author

digitalkaoz commented Apr 14, 2024 via email

@digitalkaoz
Copy link
Author

digitalkaoz commented Apr 14, 2024 via email

@ejexxeffer
Copy link

I have the same problem. And here is simple reproduction on stackblitz: https://stackblitz.com/~/github.com/ejexxeffer/datepickertest

@JarvisH
Copy link

JarvisH commented Apr 15, 2024

Same here, I also have this issue.

@digitalkaoz
Copy link
Author

@ejexxeffer thanks for taking the extra mile, our project is so big that it would have taken me an probably extraordinary amount of work to synthesize a MRB

@AriPerkkio
Copy link
Member

AriPerkkio commented Apr 15, 2024

Now that v8-to-istanbul is bundled in @vitest/coverage-v8@1.5.0 there's require() in the bundled dist/provider.js. This line throws error now: https://github.com/istanbuljs/v8-to-istanbul/blob/fcc2e35891f9034ba5d283477e6da15336cb7372/lib/v8-to-istanbul.js#L15. This is working fine in Vitest's monorepo and in ecosystem-ci projects. I wonder what's triggering the error.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/home/ejexxeffer/datepickertest/node_modules/@vitest/coverage-v8/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

@digitalkaoz
Copy link
Author

digitalkaoz commented Apr 15, 2024

then it wont work in vite5 (which defaults to ESM now) (at least with the proposed default setting type:"module" in package.json )

@AriPerkkio AriPerkkio added feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels Apr 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: coverage Issues and PRs related to the coverage feature p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants