testivai init
Scaffolds TestivAI in your project. In a Playwright project it sets up local mode with the dedicated reporter. For other frameworks it runs the interactive setup wizard.
Usage
npx testivai init [options]
Options
| Flag | Description |
|---|---|
-f, --force | Overwrite existing files (including .testivai/config.json) |
-y, --yes | Skip prompts and auto-detect framework (non-Playwright projects) |
--json | Print a machine-readable result to stdout (Playwright projects) |
Detection Order
init checks for Playwright first, before any prompt or framework
detection:
- Playwright — if
@playwright/testorplaywrightappears in yourpackage.jsondependencies or devDependencies, the command runs the local scaffold and exits. No prompts. -y, --yes— skips the wizard, auto-detects the framework, and writestestivai.config.tsplus per-framework setup instructions.- Otherwise the interactive wizard runs.
Interactive Wizard
Without flags, in a non-Playwright project, the wizard asks:
- Mode — choosing Local creates
.testivai/config.json(mode: "local") and.testivai/baselines/, adds the.gitignoreentries, and stops there - Language — JavaScript/TypeScript, Python, Java, or Ruby
- Framework — framework choices based on language
- Test directory — where to place generated example files
? Select mode: › Local — visual diffs on your machine, HTML reports
? Select your language: › JavaScript / TypeScript
? Select your test framework: › Cypress
? Where are your test files? › cypress/e2e
Cancelling the wizard (Ctrl-C) prints Setup cancelled. and exits 0.
Generated Files
After the language/framework path of the wizard, the following are created in your project:
- A helper file (
testivai-witness.js/testivai_witness.py/ etc.) — the capture function wrapper - An example test showing a complete working test with a
witness()call testivai.config.ts— project configuration
Existing files are skipped and listed as ⚠ Skipped (exists) unless --force
is passed.
For Cypress, the wizard also creates cypress.config.js with the required
plugin for remote debugging port injection — or, if one already exists, prints
the setupNodeEvents snippet for you to paste in.
Playwright Projects
If @playwright/test or playwright is detected in your package.json, testivai init scaffolds the local reporter flow:
- Creates
.testivai/config.jsonwithmode: "local"(skipped if a config already exists, unless--forceis set) - Creates the
.testivai/baselines/directory - Adds
.gitignoreentries for.testivai/temp/andvisual-report/ - Prints the reporter snippet to add to
playwright.config.tsplus a capture example
The command is idempotent — existing config is left untouched without --force — and always exits 0.
--json Output (Playwright)
npx testivai init --json
# {"framework":"playwright","mode":"local","created":[".testivai/config.json",".testivai/baselines/",".gitignore"]}
What You See
✓ TestivAI is set up for Playwright (local mode).
✓ .testivai/config.json
✓ .testivai/baselines/
✓ .gitignore
1. Add the reporter to playwright.config.ts:
reporter: [['list'], ['@testivai/witness-playwright/reporter']],
2. Capture a snapshot in a test:
import { witness } from '@testivai/witness-playwright';
await witness(page, testInfo, 'homepage');
3. Run, review, approve:
npx playwright test
open visual-report/index.html
npx testivai approve --all # then commit .testivai/baselines/