Skip to content

Add Playwright fixture for CSS coverage collection#135

Merged
bartveneman merged 11 commits into
mainfrom
claude/implement-issue-134-ozXd3
May 16, 2026
Merged

Add Playwright fixture for CSS coverage collection#135
bartveneman merged 11 commits into
mainfrom
claude/implement-issue-134-ozXd3

Conversation

@bartveneman
Copy link
Copy Markdown
Member

Summary

This PR adds a new Playwright fixture that enables automatic CSS coverage collection and reporting for individual tests. The fixture integrates with Playwright's built-in coverage API and outputs results as JSON files that can be analyzed with the existing CLI tools.

Key Changes

  • New Playwright fixture module (src/playwright/index.ts): Exports a custom test fixture that extends Playwright's base test with CSS coverage collection capabilities

    • cssCoverage fixture: Automatically starts/stops CSS coverage for each test and writes results to disk
    • cssCoverageDir option: Configurable output directory (defaults to css-coverage)
    • Generates sanitized filenames based on test title paths
    • Attaches coverage JSON files to Playwright HTML reports
  • Build configuration: Added tsdown entry point for the new Playwright module with proper ESM output and external dependency handling

  • Package exports: Updated package.json to expose the new fixture via @projectwallace/css-code-coverage/playwright subpath export

  • Documentation: Added comprehensive usage guide in README covering:

    • How to extend fixtures with the CSS coverage fixture
    • Example test implementation
    • Configuration options
    • Integration with the CLI tools

Implementation Details

  • The fixture sanitizes test title paths to create valid filenames (removing special characters, converting to lowercase)
  • Coverage data is written as JSON and automatically attached to test reports for easy access
  • The cssCoverageDir is a worker-scoped option, allowing configuration at the test suite level
  • The fixture properly handles async operations and integrates with Playwright's test lifecycle

https://claude.ai/code/session_018rtpbM5EyF5KJTUBiA7JSc

claude added 2 commits May 15, 2026 13:49
Exposes a `test` fixture via `@projectwallace/css-code-coverage/playwright`
that starts/stops CSS coverage around each test and writes JSON files to
disk automatically. The output directory defaults to `css-coverage` and
is configurable via the `cssCoverageDir` fixture option in playwright.config.ts.

Closes #134
Users should explicitly request cssCoverage in each test rather than
having it run automatically for all tests. The expect re-export was
unnecessary since users import it directly from @playwright/test.
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 15, 2026

Bundle Report

Bundle size has no change ✅

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.76%. Comparing base (946d694) to head (8e5f78b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #135   +/-   ##
=======================================
  Coverage   96.76%   96.76%           
=======================================
  Files          14       14           
  Lines        1081     1081           
  Branches      143      143           
=======================================
  Hits         1046     1046           
  Misses         34       34           
  Partials        1        1           

☔ 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.

claude added 9 commits May 15, 2026 13:58
…Tests usage

- Tests cover: configured output directory, default directory, file naming
  from titlePath, and file content being valid JSON coverage data
- Drop scope: 'worker' from cssCoverageDir so it can be set per describe
  block with test.use() — worker-scoped options can only be set at file
  top-level which is too restrictive for users
- Use mergeTests() instead of test.extend() when composing the fixture,
  which is the correct Playwright API for merging test objects
- Update README to reflect mergeTests usage
- Extract slugify() as a named exported function in the playwright fixture
  with a comment explaining why it's needed (titlePath entries contain '/'
  which would otherwise create subdirectories)
- Import slugify in tests instead of duplicating the regex logic
- Extract repeated HTML string to TEST_CONTENT const in tests
- Collapse beforeEach auto-coverage example to a single line in README
Avoids importing @playwright/test entirely, removing the implicit
dependency that would require it as a peerDependency or dependency
in the published package. Users wire save_css_coverage() into their
own Playwright fixture, keeping full control over the fixture lifecycle.

Tests no longer need a browser — mock coverage data is passed directly
to save_css_coverage(), making them faster and simpler.
The subpath added no real value once reduced to a plain helper function.
The full fixture setup is simple enough to paste directly, and keeping it
in the README means users own the code and can adapt it freely.
@bartveneman bartveneman merged commit 4b8d4f0 into main May 16, 2026
5 of 6 checks passed
@bartveneman bartveneman deleted the claude/implement-issue-134-ozXd3 branch May 16, 2026 09:42
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.

3 participants