All coverage missing, minimal example #5964
-
I'm trying to use Vitest to report code coverage with a minimum viable library. The library is set up as shown below:
Note that "exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/fibonacci.cjs",
"default": "./dist/fibonacci.modern.js"
}
}, Tests pass, but coverage is always empty:
I'm experiencing the problem in a larger project, but stripped it down as much as possible to the fibonacci sample shown here. Things I've tried, without success:
No errors or warnings, just 0% coverage. Does Vitest coverage support sourcemaps? Possible that this is related to v8 or istanbul, but given that the issue is happening with both, I thought I'd start opening a discussion here. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Could you convert that zip-file into Github repository or use https://vitest.new ?
Yes, and we have test case for this:
The test case runs |
Beta Was this translation helpful? Give feedback.
Thanks for minimal repros, it was easy to debug the root cause using those. 👍
This is a bug that's related to
dist
name specifically.vitest/packages/vitest/src/defaults.ts
Lines 13 to 15 in 0eda99d
Here the
defaultExclude
is a hard coded default in Vitest. Thethis.options.exclude
is what user sets incoverage.exclude
. We should only usethis.options.exclude
here, and adddefaultExclude
to its default values. Then user could explicitly disable ignoringdist
directory. Right now it's not possible asdefaultExclude
is always used.vitest/packages/coverage-v8/src/provider.ts
Line 133 in 0eda99d