Skip to content

test: Add Vitest test infrastructure#25

Open
skid-dev wants to merge 1 commit into
claude/recursing-goldberg-5b5636from
claude/vitest-infrastructure
Open

test: Add Vitest test infrastructure#25
skid-dev wants to merge 1 commit into
claude/recursing-goldberg-5b5636from
claude/vitest-infrastructure

Conversation

@skid-dev
Copy link
Copy Markdown
Owner

Summary

Sets up Vitest with WXT's WxtVitest() plugin so unit tests can run against the real WXT config and use fakeBrowser for chrome.* APIs. Uses happy-dom for DOM globals (added because the WXT plugin alone doesn't provide one).

  • vitest.config.ts registers WxtVitest() and sets test.environment = "happy-dom".
  • New devDeps: vitest@^3.0.0, @vitest/coverage-v8@^3.0.0, happy-dom@^15.0.0.
  • New npm scripts: test, test:watch, test:coverage.
  • README gains a ### Testing subsection documenting the commands.

Smoke tests

  • src/background/set_setting.test.ts — seeds chrome.storage.sync via fakeBrowser, verifies the target key updates without dropping siblings, and verifies the uninitialized-storage path logs Settings not initialized yet. without touching storage.
  • src/content/auto_detection/show_banner.test.ts — mounts the banner into document.body, asserts id/top/right/zIndex/position and innerHTML content, then uses vi.useFakeTimers() + vi.advanceTimersByTime(10000) to assert it removes itself. A third case exercises a custom auto_hide_ms.

Test plan

  • npm install --ignore-scripts succeeds
  • npx wxt prepare succeeds
  • npm run typecheck passes
  • npm run test — 5 tests pass across 2 files
  • npm run build still succeeds (no regression to the chrome-mv3 output)
  • Files pass prettier --check against the project's .prettierrc

Notes for the reviewer

  • Targets claude/recursing-goldberg-5b5636 (the WXT migration branch from Migrate build system from Webpack to WXT #22). Once that merges to main, this PR can be retargeted.
  • The task spec said set_setting should "error out" when storage isn't initialized. The actual implementation logs to console.error and returns — the test verifies that observable behavior rather than asserting a thrown error.

🤖 Generated with Claude Code

Sets up Vitest with WXT's `WxtVitest()` plugin so unit tests can run
against the real WXT config and use `fakeBrowser` for `chrome.*` APIs.
Uses happy-dom for DOM globals.

Adds two smoke test files:
- src/background/set_setting.test.ts — verifies sibling settings are
  preserved on update and that uninitialized storage logs the expected
  error without writing.
- src/content/auto_detection/show_banner.test.ts — mounts the banner,
  asserts id/style/content, and advances fake timers to confirm the
  default 10s and custom auto-hide cleanup.

New npm scripts: test, test:watch, test:coverage.
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.

1 participant