Skip to content

Commit 5af68f0

Browse files
committed
test: Add Vitest test infrastructure
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.
1 parent 58d9d76 commit 5af68f0

6 files changed

Lines changed: 362 additions & 11 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@ To manually load the production build as an unpacked extension in Chrome:
5959
3. Enable Developer Mode (top right).
6060
4. Click "Load Unpacked" and select the `.output/chrome-mv3/` folder.
6161

62+
### Testing
63+
64+
Unit tests use [Vitest](https://vitest.dev) with WXT's `WxtVitest()` plugin, which wires up the `fakeBrowser` from `@webext-core/fake-browser` so `chrome.*` APIs work in-process. DOM globals (`document`, `window`, etc.) are provided by [`happy-dom`](https://github.com/capricorn86/happy-dom). Test files live alongside the code as `*.test.ts`.
65+
66+
```bash
67+
# run the full suite once
68+
npm run test
69+
70+
# re-run on file changes
71+
npm run test:watch
72+
73+
# collect coverage with v8
74+
npm run test:coverage
75+
```
76+
6277
## License
6378

6479
- MIT license. Do whatever you want idrc

0 commit comments

Comments
 (0)