Skip to content

@extension-use/testing ​

Test your controller code at two levels: fast unit tests against a mock host, and browser tests that load your real extension with Playwright.

bash
npm install -D @extension-use/testing

For browser tests, also install @playwright/test (1.45 or newer) and run npx playwright install chromium once.

Entry points ​

ImportExports
@extension-use/testingcreateMockHost(), expectErrorCode()
@extension-use/testing/playwrighttest (with extension fixtures), expect, controllerIn()

createMockHost(options?) ​

Runs the real router over an in-memory transport. You supply the results of the actions your code uses.

OptionMeaning
handlersResults for built-in actions, by name. Actions without one aren't offered (UNKNOWN_ACTION).
actionsYour own actions, run for real.
grantsGrants for connected controllers. Default ["*"].
tabThe tab every call targets. Default: tab 1 on https://example.com/.
policySite policy, as in defineHost().
validateOutputCheck handler results against each action's output schema. Default true.

The host has connect(), calls, callsTo(action), emit(name, payload, tabId?), setHandler(action, handler) and router (for pause()).

expectErrorCode(promise, code) resolves with the ExtensionUseError if the promise rejects with that code, and fails otherwise.

Playwright fixtures ​

FixtureWhat it is
extensionPath (option)Your built, unpacked extension. Set it in use in playwright.config.
panelPath (option)The extension page that mounts the frame bridge. Default "sidepanel.html".
extensionHeadless, extensionArgs (options)Run headless (default, unless HEADED=1), and extra Chromium switches.
contextChromium with your extension loaded.
extensionId, serviceWorkerThe extension's ID and its service worker.
openPanel({ path?, frameUrl? })Opens the side panel page as a tab and returns { page, frame, ext }.

controllerIn(pageOrFrame) drives the client a page exposed with connect(…, { expose: true }). Its ext.call() rejects with an ExtensionUseError, and ext.try() returns { ok, output } or { ok: false, code, message }.

See the testing guide for examples.

The SDK packages are released under the MIT license.