Skip to content

[coverage] Support collecting and formatting Web (V8 / Chrome) coverage reports #2434

Open

Description

@kevmoo

Currently, package:coverage utilities (such as test_with_coverage, collect_coverage, and format_coverage) are designed around the Dart VM Service API and gather coverage metrics exclusively from Dart VM isolates.

When running tests targeting web or browser platforms (e.g. dart test -p chrome), package:test collects V8 JavaScript JSON coverage files (e.g. my_test.dart.chrome.json). However:

  1. dart run coverage:test_with_coverage does not support collecting or orchestrating web/Chrome test runs.
  2. Running collect_coverage against a -p chrome test run produces an empty VM coverage file ({"type":"CodeCoverage","coverage":[]}).
  3. Collecting code coverage across full-stack applications (where backend Shelf SSR runs on the VM and frontend components run in V8) requires manual multi-step compilation and formatting.

It would be fantastic if package:coverage (test_with_coverage and format_coverage) could natively support collecting, parsing, and unifying Web/V8 JS coverage data alongside Dart VM coverage into a single LCOV report.

Related context / demand: See also #471 where developers run into hangs attempting to use --coverage with -p chrome.

Activity

  1. self-assigned this
    on Jul 1, 2026
  2. kevmoo commented on Aug 13, 2026

    @kevmoo
    MemberAuthor

    Partial progress on this in #2448, which covers the first two points: test_with_coverage can now orchestrate web/Chrome runs via -p chrome, and those runs produce real coverage instead of an empty {"type":"CodeCoverage","coverage":[]}.

    The third point — unifying web and VM coverage into a single LCOV report, for the full-stack case — is deliberately not in that PR, so I've marked it Towards rather than Fixes. Two things I learned while scoping it, for whoever picks it up:

    It requires giving up function coverage. Merging means running both platforms in one dart test --coverage invocation (the VM-service pause/resume flow can't be combined with the browser flow in a single run). dart test --coverage emits line coverage only — verified: no funcHits/funcNames in its output even for VM suites. So a unified mode would have to reject --function-coverage.

    The merge semantics need a deliberate decision. Web coverage is measured on compiled JavaScript, so the two platforms track genuinely different line sets: code the compiler tree-shakes cannot be reported as uncovered at all. Merging takes the union, so a line covered on the VM but absent from the web build reads as covered. For "is this code tested anywhere" — the full-stack question — that is the right answer. For "is my frontend actually tested" it hides platform gaps, and --fail-under would gate on the union.

    Mechanically the change looks small: package:test already accepts -p vm,chrome and writes both .vm.json and .chrome.json into one directory, and HitMap.parseFiles already merges them. The design questions above are the real work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions