Skip to content

Run test suite in real Chromium via vitest browser mode - #6

Merged
myabc merged 1 commit into
mainfrom
code-maintenance/vitest
Aug 10, 2026
Merged

Run test suite in real Chromium via vitest browser mode#6
myabc merged 1 commit into
mainfrom
code-maintenance/vitest

Conversation

@myabc

@myabc myabc commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Ticket

N/A — infrastructure groundwork for the selector-scoping stack (#1, #2, #4).

What are you trying to accomplish?

Run the test suite in a real browser. happy-dom restricts querySelector combinator matching to the query root's subtree, which is non-spec — real browsers match document-wide and filter results to descendants. That divergence sits exactly on this library's core domain, selector resolution: the :scope anchoring tests in #4 pass vacuously under happy-dom (verified by mutation canary — they stayed green with anchoring disabled). Landing this first means the whole stack gets verified in a real browser.

What approach did you choose and why?

Vitest browser mode with the Playwright provider, all tests headless in Chromium — not a hybrid split. The library is DOM-first and tiny (33 tests on main, ~1.2s total), so one runner/one config beats maintaining a unit/browser split; pure-logic tests run fine in the browser too.

  • Imports migrated bun:testvitest (spyOnvi.spyOn); happy-dom, test/setup.ts, and the bunfig.toml preload deleted.
  • New environment guard test asserts spec-correct document-wide combinator matching, so a regression to an emulated DOM is caught immediately.
  • playwright declared explicitly in devDependencies (non-optional peer of @vitest/browser-playwright), so bunx playwright matches the provider's expectations.
  • CI installs the Playwright Chromium binary (bunx playwright install chromium --with-deps); Bun stays as package manager/runtime.
  • CLAUDE.md records the exception to its bun test default. Firefox/WebKit matrix deliberately skipped for now — :scope is baseline everywhere.

No changeset: test infrastructure only, no published behavior change.

Replaces #5, which GitHub's stack feature would not let retarget from fix/scope-selectors to main; #1/#2/#4 rebase on top of this.

Verification: bun run test 33 pass in Chromium, bun run build clean.

Merge checklist

  • Added/updated tests
  • Lookbook docs n/a — npm library
  • Tested major browsers — entire suite now runs in real Chromium on every CI push

happy-dom restricts querySelector combinator matching to the query
root's subtree, which is non-spec: real browsers match document-wide
and only filter results to descendants. That divergence sits exactly
on this library's core domain — selector resolution — so bugs in
scoping behaviour can be invisible to an emulated-DOM suite.

Switch the runner to vitest browser mode with the Playwright
provider, executing all tests headless in Chromium:

- migrate imports bun:test -> vitest (spyOn -> vi.spyOn); drop
  happy-dom, test/setup.ts, and bunfig.toml preload
- add an environment guard test asserting spec-correct document-wide
  combinator matching, so a regression to an emulated DOM is caught
- declare playwright explicitly in devDependencies (non-optional peer
  of @vitest/browser-playwright) so bunx playwright matches the
  provider's expectations
- CI installs the Playwright chromium binary before running
- record the bun-test exception in CLAUDE.md

Suite: 33 pass in ~1.2s.
Copilot AI lite review requested due to automatic review settings August 10, 2026 19:38

Copilot AI 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.

Pull request overview

This PR migrates the project’s test execution from Bun’s in-process runner + happy-dom to Vitest browser mode backed by Playwright, so selector semantics are exercised in real headless Chromium (closing the spec gap that hid selector scoping issues).

Changes:

  • Add Vitest browser-mode configuration using the Playwright provider (Chromium headless).
  • Migrate tests from bun:test to vitest (spyOnvi.spyOn) and remove happy-dom registration/preload.
  • Update CI to install the Playwright Chromium browser and run vitest run via bun run test.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vitest.config.ts Adds Vitest browser-mode config using Playwright/Chromium headless.
test/setup.ts Removes happy-dom global registrator setup (no longer needed).
test/query.test.ts Switches test imports/mocking from bun:test to vitest (vi).
test/integration.test.ts Switches test imports/mocking from bun:test to vitest (vi).
test/helpers.test.ts Switches test imports from bun:test to vitest.
test/harness.test.ts Replaces happy-dom registration check with DOM availability + adds spec-guard test for combinator matching.
test/blessing.test.ts Switches test imports/mocking from bun:test to vitest (vi).
test/barrel.test.ts Switches test imports from bun:test to vitest.
package.json Updates test script to vitest run and adds Vitest/Playwright dev dependencies.
CLAUDE.md Documents the testing exception: Vitest browser mode in real Chromium (vs bun test).
bunfig.toml Removes Bun test preload configuration (no longer applicable).
bun.lock Locks added/removed dependencies for Vitest browser mode and Playwright.
.github/workflows/test.yml Installs Playwright Chromium in CI and runs tests via bun run test.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@myabc
myabc merged commit aa984f5 into main Aug 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants