Skip to content

Extend test fixtures

Use test.extend() when several tests need the same launch and setup. Keep one-off files and options in the test that uses them.

import { fileURLToPath } from 'node:url';
import type { TerminalHarness } from 'termwright';
import { expect, test as base } from 'termwright/test';
const editor = fileURLToPath(new URL('../editor.js', import.meta.url));
const test = base.extend<{ app: TerminalHarness }>({
app: async ({ terminal }, use) => {
const app = await terminal.launch({
command: [process.execPath, editor],
files: { 'config.json': '{}' },
});
await app.waitForText('Ready');
await use(app);
},
});
test('saves on Ctrl+S', async ({ app }) => {
await app.press('Control+s');
await expect(app).toHaveText('Saved');
});

The custom fixture is typed alongside terminal, step, and the other Termwright fixtures. Teardown runs inside-out, so the terminal session remains available while the custom fixture finishes its cleanup.

Use test.override() to change launch defaults for a file or nested describe:

import { describe, test } from 'termwright/test';
test.override({ termwrightOptions: { columns: 120, trace: 'on' } });
describe('wide layout', () => {
test.override({ termwrightOptions: { columns: 200 } });
// Tests here use 200 columns. Other tests in the file use 120.
});

Suite overrides merge between project configuration and an individual launch:

configureTermwright() < test.override() < terminal.launch()

env and timeouts merge by key. command replaces the complete argv rather than concatenating argument lists. See Configuration for the exact option surface.

SetupRecommended location
Files needed by one caseterminal.launch({files}) in that case
Shared project treeterminal.launch({template})
Reusable launch and login flowtest.extend() fixture
Viewport or trace default for a suitetest.override()
Project-wide defaultconfigureTermwright()

See Test files and isolation for working-directory behavior.