Skip to content

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

Closed
myabc wants to merge 1 commit into
fix/scope-selectorsfrom
code-maintenance/vitest
Closed

Run test suite in real Chromium via vitest browser mode#5
myabc wants to merge 1 commit into
fix/scope-selectorsfrom
code-maintenance/vitest

Conversation

@myabc

@myabc myabc commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Ticket

N/A — follow-up to the selector-scoping work in #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: the :scope anchoring integration tests in #4 passed vacuously (green even with anchoring disabled), and the original scoping leak was invisible to the suite.

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 (60 tests, ~2.4s 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.
  • 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.

Proof the migration achieves its goal — mutation canary: with anchorToScope neutered to the identity function, the previously-vacuous anchoring tests now fail (12 failures, including combinators cannot match through ancestors outside the root); reverted after checking. Firefox/WebKit matrix deliberately skipped for now — :scope is baseline everywhere.

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

Stacked on #4; chain #1#2#4 ← this.

Verification: bun run test 60 pass in Chromium, bun run typecheck clean, 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

Copilot AI lite review requested due to automatic review settings August 10, 2026 19:10
@myabc myabc added the enhancement New feature or request label Aug 10, 2026

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

Migrates the project’s test runner from Bun’s bun:test + happy-dom to Vitest browser mode backed by Playwright Chromium, so selector scoping behavior is validated against real browser querySelector semantics.

Changes:

  • Adds Vitest browser-mode configuration (Playwright provider) and updates CI to install Chromium and run vitest run.
  • Updates all test imports/spies from bun:test to vitest (spyOnvi.spyOn) and removes happy-dom registration/preload.
  • Adds an environment-guard test asserting spec-correct document-wide combinator matching.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Enables Vitest browser mode with the Playwright provider and Chromium instance.
test/setup.ts Removes happy-dom global registration (no longer needed under real Chromium).
test/query.test.ts Migrates test APIs to Vitest and updates commentary to reflect real-browser execution.
test/integration.test.ts Migrates to Vitest APIs (vi.spyOn).
test/helpers.test.ts Migrates to Vitest APIs.
test/harness.test.ts Updates harness check and adds a DOM-semantics environment guard test.
test/element-definition.test.ts Migrates to Vitest APIs (vi.spyOn).
test/blessing.test.ts Migrates to Vitest APIs (vi.spyOn).
test/barrel.test.ts Migrates to Vitest APIs.
package.json Switches test script to vitest run and adds Vitest browser deps.
CLAUDE.md Documents the testing exception (Vitest browser mode vs bun test).
bunfig.toml Removes Bun test preload config.
bun.lock Updates lockfile for Vitest/Playwright-related dependencies.
.github/workflows/test.yml Installs Playwright Chromium in CI and runs the new test command.

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

Comment thread package.json
@myabc
myabc force-pushed the code-maintenance/vitest branch from 13ac1fb to 46a6f7d Compare August 10, 2026 19:32
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.
@myabc
myabc force-pushed the code-maintenance/vitest branch from 46a6f7d to 7367ed0 Compare August 10, 2026 19:37
@myabc

myabc commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 Closing: GitHub's stack feature blocks retargeting this PR's base to main. Replaced by a standalone PR from the same branch, rewritten against main so it can land first.

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

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

2 participants