Secure, test, and publish
Test the extension
Combine pure module tests, a repeatable manual matrix, and browser automation for the critical save-and-show journey.
8 minute lesson
Not every extension API is easy to unit-test, but core logic and complete browser behavior can still be covered deliberately.
Extract URL keys and validation into pure modules. Test them with Node. Maintain a manual matrix for restricted pages, restarts, permissions, keyboard use, and upgrades. Use a browser automation profile that loads the unpacked extension for the primary journey.
Arrange tests by boundary. Pure tests cover normalization, message parsing, and state transitions. Integration tests use small fake API adapters to verify storage rejection and missing-tab behavior. Browser tests prove the packaged manifest, permissions, contexts, DOM injection, and actual extension lifecycle work together.
Lifecycle tests are essential in Manifest V3. Let the worker become idle, close and reopen the popup, reload the extension while a page remains open, navigate across origins, and upgrade from a package containing existing data. Keeping DevTools open can change worker and popup behavior, so rerun the critical path without inspectors attached.
Assert evidence rather than absence of obvious failure: one stored record, one injected root, a defined response, no unexpected network request, and the correct accessible name and focus target. Give test profiles deterministic pages and clear stored data between independent cases.
Test key normalization, hostile text rendering, concurrent saves, close and reopen, duplicate injection, toggle after worker restart, reload with a stale content script, denied or expired access, restricted pages, keyboard-only use, and an upgrade preserving existing notes. Record which layer catches each regression.
Lesson completed