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

Extremely slow coverage with v8, and nestjs while using testing modules #5322

Closed
6 tasks done
Seboran opened this issue Mar 1, 2024 · 2 comments
Closed
6 tasks done
Labels
duplicate This issue or pull request already exists feat: coverage Issues and PRs related to the coverage feature

Comments

@Seboran
Copy link

Seboran commented Mar 1, 2024

Describe the bug

When running coverage on a nestjs project which uses @nestjs/testing, the report is very slow to report.

On my machine (Macbook pro M2), it takes around 1m for one test with one mock.

It looks like #5252, but the PR still doesn't fix the issue on my machine (if I linked the project correctly on my machine).

Maybe there is something I don't understand with nestjs that makes coverages extremely slow?

Reproduction

  1. Clone and install https://github.com/Seboran/nest-js-slow-coverage
  2. run pnpm vitest run --coverage
  3. wait for coverage to take close to a minute even tho there is only one test that does one thing
  4. check https://github.com/Seboran/nest-js-slow-coverage/blob/main/src/tools/__test__/test.service.spec.ts and see that the test doesn't do a lot

System Info

System:
    OS: macOS 14.2.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 304.98 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.5.0 - ~/.nvm/versions/node/v20.5.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.5.0/bin/npm
    pnpm: 8.5.1 - /opt/homebrew/bin/pnpm
    bun: 1.0.18 - ~/.bun/bin/bun
  Browsers:
    Safari: 17.2.1
  npmPackages:
    @vitest/coverage-v8: ^1.3.1 => 1.3.1
    @vitest/ui: ^1.3.1 => 1.3.1
    vitest: ^1.3.1 => 1.3.1

Used Package Manager

pnpm

Validations

@AriPerkkio
Copy link
Member

It looks like #5252, but the PR still doesn't fix the issue on my machine (if I linked the project correctly on my machine).

This is indeed duplicate of #5252. By patching the fix from #5259 your reproduction works fast.

  • package.json
  "pnpm": {
    "patchedDependencies": {
      "@vitest/coverage-v8@1.3.1": "patches/@vitest__coverage-v8@1.3.1.patch"
    }
  • patches/@vitest__coverage-v8@1.3.1.patch
diff --git a/dist/provider.js b/dist/provider.js
index 408c1c8d7c5053bd9d2d053717ea6d86140b34e9..0a15cfc5c641f3ecf4f1320d88a71524c8a2bac7 100644
--- a/dist/provider.js
+++ b/dist/provider.js
@@ -170,7 +170,7 @@ function cleanUrl(url) {
 
 const WRAPPER_LENGTH = 185;
 const VITE_EXPORTS_LINE_PATTERN = /Object\.defineProperty\(__vite_ssr_exports__.*\n/g;
-const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes"(\s|.)+?]\),/g;
+const DECORATOR_METADATA_PATTERN = /_ts_metadata\("design:paramtypes", \[[^\]]*?\]\),*/g;
 const DEFAULT_PROJECT = Symbol.for("default-project");
 const debug = createDebug("vitest:coverage");
 let uniqueId = 0;
$ time pnpm run test:cov --run

> backend@0.0.1 test:cov /workspaces/nest-js-slow-coverage
> vitest --coverage "--run"

The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details.

 RUN  v1.3.1 /workspaces/nest-js-slow-coverage
      Coverage enabled with v8

 ✓ src/tools/__test__/test.service.spec.ts (1)
   ✓ ToolsService (1)
     ✓ createTool (1)
       ✓ should create a new tool

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  07:37:35
   Duration  898ms (transform 114ms, setup 0ms, collect 513ms, tests 12ms, environment 0ms, prepare 132ms)

 % Coverage report from v8
-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |   46.83 |       25 |   16.66 |   46.83 |                   
 src               |       0 |        0 |       0 |       0 |                   
  app.module.ts    |       0 |        0 |       0 |       0 | 1-15              
  main.ts          |       0 |        0 |       0 |       0 | 1-15              
 src/schemas       |     100 |      100 |     100 |     100 |                   
  tool.schema.ts   |     100 |      100 |     100 |     100 |                   
 src/tools         |      80 |      100 |   33.33 |      80 |                   
  tools.service.ts |      80 |      100 |   33.33 |      80 | 14-15,18-19       
 src/tools/mock    |       0 |        0 |       0 |       0 |                   
  MockToolModel.ts |       0 |        0 |       0 |       0 | 1-8               
-------------------|---------|----------|---------|---------|-------------------

real    0m2.411s
user    0m2.099s
sys     0m1.313s

@AriPerkkio AriPerkkio closed this as not planned Won't fix, can't repro, duplicate, stale Mar 2, 2024
@AriPerkkio AriPerkkio added duplicate This issue or pull request already exists feat: coverage Issues and PRs related to the coverage feature and removed pending triage labels Mar 2, 2024
@Seboran
Copy link
Author

Seboran commented Mar 2, 2024

Oops sorry for the duplicate and thank you for the answer 😄

@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists feat: coverage Issues and PRs related to the coverage feature
Projects
None yet
Development

No branches or pull requests

2 participants