Skip to content

Add native JavaScript coverage for browser runtime#343

Merged
aallan merged 3 commits into
mainfrom
feat/js-coverage
Mar 24, 2026
Merged

Add native JavaScript coverage for browser runtime#343
aallan merged 3 commits into
mainfrom
feat/js-coverage

Conversation

@aallan

@aallan aallan commented Mar 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Collect V8 coverage from browser parity tests using NODE_V8_COVERAGE env var
  • Convert to LCOV via npx c8 report and upload to Codecov with javascript flag
  • Add codecov.yml with python/javascript flags and carryforward: true
  • Add tests/conftest.py with opt-in local JS coverage (VERA_JS_COVERAGE=1)
  • Zero changes to test_browser.py — coverage is collected via env var inheritance

How it works

Node.js writes V8 coverage JSON for every node process when NODE_V8_COVERAGE is set. Since _run_node() calls subprocess.run() without env=, child processes inherit the parent environment automatically. Each subprocess writes uniquely-named coverage files. After all tests, npx c8 report merges them into a single LCOV file.

Local usage

VERA_JS_COVERAGE=1 pytest tests/test_browser.py -v -s

Current JS coverage baseline

File Stmts Branch Funcs Lines
harness.mjs 93.26% 86.66% 100% 93.26%
runtime.mjs 63.52% 65.6% 53.65% 63.52%

Closes #337

Test plan

  • All 21 pre-commit hooks pass
  • VERA_JS_COVERAGE=1 pytest tests/test_browser.py -v -s prints JS coverage table
  • python scripts/check_doc_counts.py passes
  • CI passes
  • Codecov shows JS coverage on this PR

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • CI now collects and uploads separate JavaScript coverage alongside Python coverage; coverage uploads carry language-specific flags.
    • Added ignores for Node.js coverage artifacts.
  • Tests

    • Browser tests can be run with an environment flag to produce JS coverage; test session now prepares and summarises V8 coverage when enabled.
  • Documentation

    • Updated testing and contribution guides with instructions for generating and reporting JavaScript coverage.

Use V8 built-in NODE_V8_COVERAGE to collect JS coverage during
browser parity tests. After tests complete, npx c8 converts the
accumulated V8 data to LCOV and uploads to Codecov with a
javascript flag. Zero changes to test_browser.py — coverage
is collected automatically via environment variable inheritance.

- CI: Add coverage steps to browser-parity job
- codecov.yml: Configure python/javascript flags with carryforward
- conftest.py: Opt-in local JS coverage via VERA_JS_COVERAGE=1
- .gitignore: Add node_modules/ and .c8_output/
- Docs: Update TESTING.md, CLAUDE.md, CONTRIBUTING.md

Closes #337

Co-Authored-By: Claude <noreply@anthropic.invalid>
@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3585462f-a652-4f5d-9591-a5bb54f39ce3

📥 Commits

Reviewing files that changed from the base of the PR and between 8d706cd and 8a2d048.

📒 Files selected for processing (1)
  • tests/conftest.py

📝 Walkthrough

Walkthrough

Adds V8/Node JavaScript coverage for browser parity tests: test harness writes V8 coverage, CI generates LCOV via c8 and uploads it to Codecov under a javascript flag, and local pytest support conditionally collects and reports V8 coverage.

Changes

Cohort / File(s) Summary
CI and Coverage Workflow
\.github/workflows/ci.yml
Set NODE_V8_COVERAGE for browser parity step, generate LCOV from V8 coverage with npx c8, upload js-coverage/lcov.info to Codecov with flags: javascript. Also added flags: python to Python upload.
Test Infrastructure
tests/conftest.py
New session-scoped autouse fixture _js_coverage_dir that creates a v8-coverage temp dir when VERA_JS_COVERAGE is set, exports NODE_V8_COVERAGE for subprocesses, and runs npx c8 report --reporter=text post-session if data exists.
Coverage Configuration
codecov.yml
New config declaring separate coverage targets/flags for python (paths under vera/) and javascript (paths under vera/browser/), with carryforward: true and patch checks set informational.
Documentation & Developer Guidance
CLAUDE.md, CONTRIBUTING.md, TESTING.md
Documented running browser tests with VERA_JS_COVERAGE=1 and CI behaviour for collecting V8 coverage; clarified which changes (e.g. vera/browser/runtime.mjs) should include JS coverage.
Version Control
\.gitignore
Added node_modules/ and .c8_output/ to ignore list to avoid checking in Node deps and c8 artefacts.

Sequence Diagram(s)

mermaid
sequenceDiagram
autonumber
participant CI as CI Runner
participant Py as pytest
participant Node as Node/c8
participant Codecov as Codecov
CI->>Py: run pytest tests/test_browser.py with VERA_JS_COVERAGE=1
Py->>Node: spawn harness (inherits NODE_V8_COVERAGE)
Node->>Node: write raw V8 coverage files to temp dir
CI->>Node: npx c8 report --reporter=lcov --report-dir=./js-coverage --temp-directory=<tmp>
Node-->>CI: produce js-coverage/lcov.info
CI->>Codecov: upload js-coverage/lcov.info with flags: javascript
CI->>Codecov: upload Python coverage with flags: python

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ci, docs, tests

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically summarises the main change: adding JavaScript coverage collection for the browser runtime via V8.
Linked Issues check ✅ Passed All primary objectives from issue #337 are met: V8 coverage collection via NODE_V8_COVERAGE, LCOV conversion via c8, Codecov upload with javascript flag, and optional local JS coverage opt-in.
Out of Scope Changes check ✅ Passed All changes are in scope: CI workflow updates, coverage configuration, test fixtures, and documentation additions directly support the JavaScript coverage implementation objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/js-coverage

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Mar 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.96%. Comparing base (ce1c110) to head (8a2d048).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
- Coverage   95.37%   91.96%   -3.42%     
==========================================
  Files          45       47       +2     
  Lines       16141    17849    +1708     
  Branches        0      211     +211     
==========================================
+ Hits        15395    16415    +1020     
- Misses        746     1430     +684     
- Partials        0        4       +4     
Flag Coverage Δ
javascript 59.71% <ø> (?)
python 95.37% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Split project/patch status into per-flag checks so JS coverage
(63%) does not drag down the Python metric (95%). Mark JS checks
as informational until the baseline stabilises.

Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan

aallan commented Mar 24, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@aallan

aallan commented Mar 24, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/conftest.py`:
- Around line 34-44: The subprocess.run call that invokes "npx c8 report" in the
teardown currently has no timeout and can hang; update the teardown to call
subprocess.run([...], check=False, timeout=<reasonable_seconds>) and catch
subprocess.TimeoutExpired around that call (referencing subprocess.run and the
"npx c8 report" invocation and cov_dir) so the test suite won’t block — on
timeout log or print a concise warning and continue/cleanup instead of letting
pytest hang.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e2e11afe-ff49-441f-9634-011ae1d8859b

📥 Commits

Reviewing files that changed from the base of the PR and between ce1c110 and 8d706cd.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • .gitignore
  • CLAUDE.md
  • CONTRIBUTING.md
  • TESTING.md
  • codecov.yml
  • tests/conftest.py

Comment thread tests/conftest.py Outdated
Co-Authored-By: Claude <noreply@anthropic.invalid>
@aallan aallan merged commit 4daac70 into main Mar 24, 2026
17 checks passed
@aallan aallan deleted the feat/js-coverage branch March 24, 2026 23:42
@aallan

aallan commented Mar 24, 2026

Copy link
Copy Markdown
Owner Author

The JS coverage setup uses a clever pattern: V8's built-in coverage (via NODE_V8_COVERAGE env var) collects raw coverage data during normal Node.js execution — no instrumentation or source transforms needed. c8 then converts this into lcov format that Codecov understands. The codecov.yml flags system means Python and JS coverage are evaluated independently, so a 63% JS score won't block PRs that only touch Python code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add native JavaScript coverage for browser runtime

1 participant