You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is fine for most projects but larger projects can run into Node's out-of-memory issues. This is common problem for coverage tools. As commented in the Istanbul's provider.ts, this was only a matter of time before Vitest started to run into these. Similar reports form others tools:
Example below demonstrates the idea. Note that this is just a simplified example. Generating reports is much more complicated:
import*asfsfrom"node:fs/promises";exportclassIstanbulCoverageProvider{pendingPromises=[]onAfterSuiteRun({ coverage, transformMode, projectName }){// Write reports to file system. Do not block the runner by `await`'in this call.// Instead store the promise for later awaitingconstpromise=fs.writeFile('some-filename.json',JSON.stringify({ coverage, transformMode, projectName }))this.pendingPromises.push(promise)}asyncreportCoverage(){// All tests have run, time to generate reportawaitPromise.all(this.pendingPromises);constcoverageMap={ ... };// Read results from file system one by one to avoid causing OOMsfor(constfilenameoffs.readdir(...)){constcoverage=JSON.stringify(fs.readFileSync(filename));coverageMap.merge(coverage);}}}
This should be possible to implement without causing breaking changes. Only the coverage providers need changes.
Describe the bug
Vitest runner sends coverage reports to main thread which stores them in memory during test run:
vitest/packages/coverage-istanbul/src/provider.ts
Lines 46 to 52 in cc19117
vitest/packages/coverage-v8/src/provider.ts
Line 59 in cc19117
This is fine for most projects but larger projects can run into Node's out-of-memory issues. This is common problem for coverage tools. As commented in the Istanbul's
provider.ts
, this was only a matter of time before Vitest started to run into these. Similar reports form others tools:Instead of storing reports in memory, we should write them on file system. This should be done in main thread here without blocking the runner.
vitest/packages/coverage-istanbul/src/provider.ts
Lines 118 to 130 in cc19117
Example below demonstrates the idea. Note that this is just a simplified example. Generating reports is much more complicated:
This should be possible to implement without causing breaking changes. Only the coverage providers need changes.
Reproduction
https://github.com/vitest-tests/coverage-large
Increase these to trigger the error: https://github.com/vitest-tests/coverage-large/blob/4bb1e194fa51c0ae03b9a7c76952a59b43540e49/generate-files.mjs#L4-L6
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: