feat(coverage): add @react-grab/playwright-coverage package - #489
Open
aidenybai wants to merge 5 commits into
Open
feat(coverage): add @react-grab/playwright-coverage package#489aidenybai wants to merge 5 commits into
aidenybai wants to merge 5 commits into
Conversation
Capture native V8 JS coverage from a Playwright run and remap it back onto original src/*.ts(x) via monocart-coverage-reports. - New package packages/playwright-coverage with createCoverageFixture (auto fixture, COVERAGE-gated, Chromium-only) and generateCoverageReport. - Merges per-test V8 dumps incrementally (one accumulator per script, drops non-remappable URLs early) so memory stays bounded across the full suite. - Reuses monocart's public Util.mergeV8Coverage range-tree merge instead of a separate @bcoe/v8-coverage dependency. - react-grab consumes it: e2e fixture, scripts/run-coverage.ts orchestrator, e2e/coverage-config.ts (dirs + react-grab source filter), and a build:coverage (sourcemapped, unminified) build wired into playwright.config under COVERAGE.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Replace the bespoke script that re-spawned `playwright test` with native hooks: clean the raw V8 dir as the config loads and generate the report in globalTeardown (both gated on COVERAGE). test:coverage is now just `COVERAGE=1 playwright test`.
Contributor
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/playwright-coverage/src/report.ts">
<violation number="1" location="packages/playwright-coverage/src/report.ts:66">
P2: `/@fs/` prefix trimming is off by one, producing incorrect local file paths. This can drop remappable scripts and under-report coverage on some platforms.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
There was a problem hiding this comment.
1 issue found across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
The perf workflow runs `playwright test` after `pnpm install` with no build step, so @react-grab/playwright-coverage's dist never exists. playwright.config and fixtures imported it at the top level, breaking config load for every perf run (ERR_MODULE_NOT_FOUND). Make the package strictly opt-in: move the raw-dir clean into a COVERAGE-only globalSetup module, and have the fixture lazily `import()` a new per-test `captureCoverage` primitive inside its body. Non-coverage (and perf) runs now never reference the package, so its build is no longer a hard dependency. Replaces the createCoverageFixture factory with the smaller captureCoverage primitive that composes with lazy loading.
Address review feedback: when COVERAGE is set, force a fresh dev server so the sourcemapped, unminified build:coverage always runs. Reusing an existing server (the default local non-CI case) could serve a minified dist with no sibling .map, silently producing empty/misleading coverage. Also self-document the /@fs/ path slice so its intent (preserve the leading slash of the absolute path) is obvious and provably not off-by-one.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e065353. Configure here.
…age run Address review feedback: - captureCoverage now stops/writes coverage in a finally, so a failing test still flushes whatever it exercised instead of dropping its coverage. - Add pretest:coverage to build @react-grab/playwright-coverage, since the coverage path imports its dist (globalSetup + fixture) and `test:coverage` alone never built it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a dedicated
@react-grab/playwright-coveragepackage that captures native V8 JS coverage from a Playwright run and remaps it back onto the originalsrc/*.ts(x)sources.packages/playwright-coverage:createCoverageFixture({ rawDir })— an auto Playwright fixture (COVERAGE-gated, Chromium-only, fully best-effort) that dumps per-test V8 coverage.generateCoverageReport(options)— merges the raw dumps, inlines the dist sourcemaps, and producesv8/lcovonly/ console reports viamonocart-coverage-reports.@bcoe/v8-coveragedependency: reuses monocart's publicUtil.mergeV8Coverage(the same bcoe range-tree merge) since we already depend on monocart for reporting.scripts/run-coverage.tsorchestrates the run;e2e/coverage-config.tsholds the dirs + react-grab source filter; a sourcemapped, unminifiedbuild:coverageis selected inplaywright.config.tsunderCOVERAGE.Run with:
pnpm --filter react-grab test:coverageTest plan
pnpm --filter @react-grab/playwright-coverage build(dist matches exports map)pnpm --filter @react-grab/playwright-coverage typecheck+lintpnpm --filter react-grab typecheck(consumer resolves package types)Util.mergeV8Coveragereachable;count:1 ∪ count:0 → 1@react-grab/playwright-coverage#buildis in react-grab's turbo build graph (pnpm buildbuilds it first)pnpm --filter react-grab test:coveragerun produces a src-level reportNote
Low Risk
Test-only and dev-tooling paths; coverage is gated on COVERAGE and does not change production runtime behavior of react-grab.
Overview
Introduces
@react-grab/playwright-coverage, a workspace package that records Chromium V8 JS coverage during Playwright tests and remaps hits onto originalsrc/*.ts(x)via inlined dist source maps and monocart-coverage-reports (v8, lcov, console). Capture and reporting are best-effort so tests never fail on coverage errors; raw dumps are merged incrementally per script and non-remappable URLs are dropped to keep memory bounded on large suites.react-grab wires this behind
COVERAGE=1: an autocoverageCapturefixture (lazy import) runs before navigation;globalSetup/globalTeardownclear.coverage-v8and emit filtered reports;playwright.config.tsusesbuild:coverage(sourcemapped, unminified) and disables reusing an existing dev server so coverage is not silently empty. Addstest:coverage,.coverage-v8in.gitignore, and lockfile entries for monocart and related deps.Reviewed by Cursor Bugbot for commit 0aaab8e. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds
@react-grab/playwright-coverageto capture native V8 JS coverage in Playwright, remap it tosrc/*.ts(x), and outputv8,lcovonly, and console reports. Coverage runs areCOVERAGE-gated, lazily loaded, cleaned inglobalSetup, reported inglobalTeardown, and always use a fresh dev server for accurate sourcemaps.New Features
@react-grab/playwright-coveragewith:captureCoverage(page, rawDir, use)to record per-test V8 JS coverage (Chromium-only), now flushes coverage in a finally block so failing tests still record.generateCoverageReport(options)to merge dumps, inline sourcemaps, and produce reports viamonocart-coverage-reports.Util.mergeV8Coverage; ignores non-remappable URLs and inlines dist maps for accurate remap.react-grabwiring: lazy import autocoverageCapturefixture;e2e/coverage-setup.tsasglobalSetup;e2e/coverage-teardown.tsasglobalTeardown.playwright.config.tsswitches tobuild:coverageand never reuses a running server underCOVERAGE. Adds.coverage-v8to.gitignore.Migration
pnpm --filter react-grab test:coverage(prebuilds@react-grab/playwright-coverageviapretest:coverage).packages/react-grab/coverage/; raw dumps inpackages/react-grab/.coverage-v8.Written for commit 0aaab8e. Summary will update on new commits.