These integration tests verify extension features by running a full copy of the extension in an instrumented browser. Most tests work by loading a test page which will check that a protection is active.
We use Playwright as a test runner. Tests are defined in the .spec.js
files in the integration-tests
folder.
Playwright tests can be run with the following npm commands:
npm run playwright
to test the Chrome MV3 extensionnpm run playwright-mv2
to test the Chrome MV2 extension (closest thing to testing Firefox MV2 extension we have until Playwright adds support for testing Firefox extensions)
If you want to re-run tests without rebuilding the extension, you can subsequently run:
npx playwright test
to run all testsnpx playright test integration-test/<file>.spec.js
to just run tests in a single file.
Our Playwright tests wrap the loading of the extension and mock blocklists/config for you, so the following steps are sufficient to get started:
- Create a new file in this folder, with the extension
.spec.js
. - Start with the following boilerplate:
import { test, expect } from './helpers/playwrightHarness'
import { forExtensionLoaded } from './helpers/backgroundWait'
test('my test', async ({ manifestVersion, page, backgroundPage, backgroundNetworkContext, context }) => {
// wait for the extension to be fully loaded
await forExtensionLoaded(context)
expect(false).toBe(true)
})
The arguments to the test function are:
manifestVersion
:2
or3
. Allows you to check which version of the extension is being tested.page
: A Page instance for loading web pages.backgroundPage
: The extension's background page, which is aPage
for MV2, orWorker
for MV3. UsebackgroundPage.evaluate
to run code in the extension's background context.backgroundNetworkContext
: A context for listening to and intercepting requests from the extension's background context with Playwright's Network APIs.context
: The BrowserContext for the test run.
Static files for tests are in the data
directory:
har
- HAR files for offline tests.staticcdn
- Mocked CDN resources to used when the extension loads.