Adopt jest-webextension-mock for chrome API stubs#143
Merged
Conversation
Replace three hand-rolled `(globalThis as unknown as { chrome: ... }).chrome
= { ... }` stubs in test files with jest-webextension-mock 4.1.1 wired
through Jest's `setupFiles`. Matches the convention used in the team's
other project.
jest-webextension-mock installs `globalThis.chrome` (and `browser`) with
jest.fn() stubs for runtime, storage, tabs, action, browserAction, and
the rest of MV2/MV3 surface. It does not include chrome.scripting (the
MV3 content-script registration API), so add a small
`chrome-mv3-extras.ts` setup file that patches that namespace in after
jest-webextension-mock's main. Wired via setupFiles in jest.config.cjs.
Test-side changes per file:
- roach-motel-annotate.test.ts: drop the inline chrome stub; aliases
chrome.runtime.sendMessage as a jest.Mock for the .mockResolvedValue /
.toHaveBeenCalledWith control surface.
- webdriver-probe-annotate.test.ts: same pattern; keeps the
callsOfType / injectCalls / detectionCalls helpers that filter the
mock's call log by message type.
- webdriver-probe-registration.test.ts: drop the local ChromeStub
interface and the per-loadModule stub object; mockImplementation on
chrome.scripting.{register,unregister,getRegistered}ContentScripts
preserves the stateful registration store.
Drop the now-unused biome-ignore in rule-engine.test.ts (the explicit
type arg on jest.requireActual<Record<string, unknown>> meant no any
flowed through, but the suppression was left behind).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
a4b4034 to
65eec0b
Compare
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
Replaces three hand-rolled `(globalThis as unknown as { chrome: ... }).chrome = { ... }` stubs with jest-webextension-mock 4.1.1, wired through Jest's `setupFiles`. Matches the convention from the team's other project.
`jest-webextension-mock` installs `globalThis.chrome` (and `browser`) with `jest.fn()` stubs for runtime, storage, tabs, action, browserAction, and the rest of the MV2/MV3 surface. It does not ship `chrome.scripting` (the MV3 content-script registration API), so a small `chrome-mv3-extras.ts` setup file patches that namespace in after `jest-webextension-mock`'s main. Both wired via `setupFiles` in `jest.config.cjs`.
Per-file changes
Side cleanup
Drops a now-stale `biome-ignore` in `rule-engine.test.ts` (the explicit `Record<string, unknown>` type arg on `jest.requireActual` meant no `any` flowed through, so the suppression was unused).
Test plan
🤖 Generated with Claude Code