Testing
Official Frameworks
WXT officially supports Vitest for unit tests and either Playwright or Puppeteer for E2E tests against Chromium browsers.
For details setting up each testing framework, see the official examples:
Unofficial Frameworks
Puppeteer and Playwright are the only E2E test runners that support Chrome Extensions. There are no other options at the time of writing.
There are other options for unit tests however, like Jest, Mocha, or node:test
. WXT does not claim to support any of them because none of them support all of WXT's features, like TypeScript or auto-imports.
If you want to try to use a different framework for unit tests, you will need to configure the environment manually:
- Auto-imports: Add
unimport
to your test environment or disable them by settingimports: false
in yourwxt.config.ts
file browser
mock: Mock thewebextension-polyfill
module globally withwxt/dist/virtual/mock-browser.mjs
- Remote Code Bundling: If you use it, configure your environment to handle the
url:
module prefix - Global Variables: If you consume them, manually define globals provided by WXT (like
import.meta.env.BROWSER
) by adding them to the global scope before accessing them (import.meta.env.BROWSER = "chrome"
) - Import paths: If you use the
@/
or~/
path aliases, add them to your test environment
Here's how Vitest is configured for reference.