test: Add Vitest test infrastructure#25
Open
skid-dev wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sets up Vitest with WXT's
WxtVitest()plugin so unit tests can run against the real WXT config and usefakeBrowserforchrome.*APIs. Useshappy-domfor DOM globals (added because the WXT plugin alone doesn't provide one).vitest.config.tsregistersWxtVitest()and setstest.environment = "happy-dom".vitest@^3.0.0,@vitest/coverage-v8@^3.0.0,happy-dom@^15.0.0.test,test:watch,test:coverage.### Testingsubsection documenting the commands.Smoke tests
src/background/set_setting.test.ts— seedschrome.storage.syncviafakeBrowser, verifies the target key updates without dropping siblings, and verifies the uninitialized-storage path logsSettings not initialized yet.without touching storage.src/content/auto_detection/show_banner.test.ts— mounts the banner intodocument.body, assertsid/top/right/zIndex/positionand innerHTML content, then usesvi.useFakeTimers()+vi.advanceTimersByTime(10000)to assert it removes itself. A third case exercises a customauto_hide_ms.Test plan
npm install --ignore-scriptssucceedsnpx wxt preparesucceedsnpm run typecheckpassesnpm run test— 5 tests pass across 2 filesnpm run buildstill succeeds (no regression to the chrome-mv3 output)prettier --checkagainst the project's.prettierrcNotes for the reviewer
claude/recursing-goldberg-5b5636(the WXT migration branch from Migrate build system from Webpack to WXT #22). Once that merges tomain, this PR can be retargeted.set_settingshould "error out" when storage isn't initialized. The actual implementation logs toconsole.errorand returns — the test verifies that observable behavior rather than asserting a thrown error.🤖 Generated with Claude Code