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
{{ message }}
Repository navigation
TypeScript: a package's coverage script is preferred, but its LCOV is never read (0% in a nested package) #15
For a TypeScript package that is not the project root, typescript_command (src/crapper/runners.py:230) runs npm run coverage when the package defines that script. The report then lands where the script puts it: for Vitest, Jest, c8 and nyc that is <package>/coverage/lcov.info. But _lcov_paths (src/crapper/coverage.py:493) reads only <root>/target/coverage/**/lcov.info and <root>/coverage/**/lcov.info. So every function of the package scores 0%, and nothing is printed, because the command exited 0.
Without the script, crapper runs Vitest itself with --coverage.reportsDirectory=<root>/target/coverage/typescript/<slug> and scores correctly. Adding a coverage script, which --help lists as the first TypeScript strategy, therefore makes coverage disappear in a monorepo.
A root without package.json, and a package app/:
app/package.json "scripts": { "test": "vitest", "coverage": "vitest run --coverage --coverage.reporter=lcov" }
devDependencies: vitest 5.0.1, @vitest/coverage-v8 5.0.1
app/src/sum.ts export function sum(values: number[]): number { … } (CC 3)
app/src/sum.test.ts one test covering every line
From the root:
crapper app/src/sum.ts
+ (…/repro/app) npm run coverage
> vitest run --coverage --coverage.reporter=lcov
sum sum 3 0.0% 12.0
app/coverage/lcov.info exists and covers src/sum.ts fully. With the coverage script removed, the same command runs
+ (…/repro/app) …/app/node_modules/.bin/vitest run --coverage --coverage.reporter=lcov --coverage.reportsDirectory=…/repro/target/coverage/typescript/app --coverage.reportOnFailure=true --coverage.include=src/sum.ts
sum sum 3 100.0% 3.0
A related silent 0%: with a plain "coverage": "vitest run --coverage", Vitest's default reporters (text, html, clover, json) write no LCOV at all, and crapper again reports 0% without a word.
Suggestions, any of them would help:
after npm run coverage in a package, also read <package>/coverage/**/lcov.info, with its paths relative to the package, as for the report crapper writes itself;
when the package uses Vitest, run Vitest directly even if a coverage script exists, keeping npm run coverage for other runners;
warn, or exit non-zero, when the coverage command succeeded but no LCOV was found for the package.
Activity