ViSnap provides a command-line interface for running visual tests. All commands work with your visnap.config.ts file.
Installation
Install as a dev dependency:
npm install -D @visnap/cliOr use with npx (no installation needed):
npx visnap [command]Global Options
All commands support these options:
--config <path>- Path to configuration file (default:visnap.config.ts)--quiet- Suppress output except errors-h, --help- Show help for command-v, --version- Show version information
Commands
init
Initialize a new ViSnap project with a configuration file:
npx visnap initCreates a visnap.config file using an interactive CLI wizard.
update
Capture baseline screenshots for all test cases:
npx visnap update [options]Options:
-i, --interactive- Select test cases interactively with search--include <pattern>- Include test cases matching pattern--exclude <pattern>- Exclude test cases matching pattern--docker- Run inside Docker container
test
Capture current screenshots and compare them with baseline screenshots:
npx visnap test [options]Options:
-i, --interactive- Select test cases interactively with search--include <pattern>- Include test cases matching pattern--exclude <pattern>- Exclude test cases matching pattern--jsonReport [path]- Output JSON report (omit path for stdout)--htmlReport [path]- Generate HTML report (omit path for default location)--docker- Run inside Docker container
validate
Validate your configuration file and check dependencies:
npx visnap validatelist
List all discovered test cases without running tests:
npx visnap listopen
Open HTML report in browser or screenshot directory:
npx visnap openConfiguration
ViSnap looks for configuration in this order:
--configoptionvisnap.config.tsvisnap.config.js
Override configuration with environment variables:
VISNAP_SCREENSHOT_DIR=./screenshots
VISNAP_THRESHOLD=0.05
visnap testTroubleshooting
Command Not Found
Install ViSnap as a dev dependency:
npm install -D @visnap/cliPermission Errors
Install Playwright browsers:
npx playwright installDocker Issues
Ensure Docker is running:
docker --versionExit Codes
0- Success1- General error2- Configuration error3- Test failures4- Dependency error