This repo is a small, self-contained reproduction using ReScript 13.0.0-alpha.7 with source maps enabled and c8 12.0.0.
src/Shapes.res has four switch expressions with 14 arms in total. test/exercise.mjs runs exactly one arm of each, so 10 arms never run. Through the source map, c8 reports all of them as covered:
$ npm install
$ npm run coverage
------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
Shapes.res | 100 | 100 | 100 | 100 |
------------|---------|----------|---------|---------|-------------------npm test builds the project and runs test/coverage.test.mjs. The test runs the exercise under c8 twice:
- Control: a copy of the generated JS with the
sourceMappingURLcomment removed. c8 reports exactly the 10 unexecuted arms as uncovered, so V8 and c8 do see them. All 14 checks pass. - Through the source map: the same check on
Shapes.res. All 10 unexecuted arms are reported with 1 hit, so 10 tests fail:
✖ area: Empty did not run
AssertionError [ERR_ASSERTION]: line "Empty => 0.0" never runs, but c8 reports 1 hits
✖ unwrap: None did not run
AssertionError [ERR_ASSERTION]: line "None => -1" never runs, but c8 reports 1 hits
…
ℹ tests 28
ℹ pass 18
ℹ fail 10The compiler emits no mappings for:
- switch arms whose body is a constant or a variable (
| Empty => 0.0,| None => -1); - the tests that pick an arm (
typeof shape !== "object",shape === "Empty",value === undefined).
c8 drops coverage ranges whose start or end can't be mapped back to the source, so nothing marks those arms as uncovered. They then inherit the hit count of the enclosing function.
Calls, operators, functions and throw are mapped. For that reason, breakpoints and stack traces mostly work while coverage is wrong. The same missing mappings also affect DevTools: a breakpoint on | None => -1 can't be set or slides to another line.
The test passes once the compiler maps every switch arm.