Skip to content

@termwright/test

@termwright/test


@termwright/test — the authoring surface for the Termwright Native Host: Vitest-powered DSL, fixtures, retry-able matchers, semantic YAML snapshots and cell snapshots. It is not a direct-Vitest compatibility preset.

Importing this module registers the matchers with expect, so a test file only ever imports test and expect from here.

import {fileURLToPath} from 'node:url';
import {test, expect} from 'termwright/test';
test('asks before running a command', async ({ terminal }) => {
const appFile = fileURLToPath(new URL('../app.js', import.meta.url));
const app = await terminal.launch({ command: [process.execPath, appFile] });
await app.waitForText('Permission required');
await expect(app).toMatchSemanticSnapshot(`
- dialog "Permission" [modal]:
- button "Approve" [focused]
- button /^Rej/
`);
await app.getByRole('button', { name: 'Approve' }).activate();
await expect(app.getByTestId('status')).toHaveText('ACTIVATED approve');
});