CLI

The spectest command runs suites and manages the test environment. All options correspond to configuration fields and may be supplied via the config file or the command line. CLI flags take precedence over spectest.config.js, which takes precedence over the built-in defaults.

npx spectest [suiteFile] [options]

Options

FlagDescriptionDefault
--config=<file>Path to an extra config filenone
--base-url=<url>Base URL of the APIhttps://localhost:8080
--test-dir=<dir>Directory containing test suites./test
--file-pattern=<regex>Regex for suite filenames\.spectest\.
--start-cmd=<cmd>Command to start the test servernpm run start
--build-cmd=<cmd>Command to build the test servernone
--running-server=<reuse|fail|kill>Handling for an already running serverreuse
--tags=<tag1,tag2>Comma-separated tags used for filtering testsnone
--rps=<number>Requests per second rate limitInfinity
--timeout=<ms>Default request timeout in milliseconds60000
--snapshot=<file>Path to write a snapshot filenone
--randomizeShuffle test ordering before executionfalse
--happyRun only tests expecting a 2xx statusfalse
--filter=<pattern>Regex or smart filter to select tests (happy, failures)none
--test-output=<summary|errors>Executed test result detail; errors includes failed-test server logs and failure reasonssummary
--verboseVerbose spectest runner/program output (separate from --test-output)false
--user-agent=<name>, --ua=<name>Browser User-Agent string or one of the predefined user-agentschrome_windows
--proxy=<url>Proxy URL to route requests throughnone
--recording=<off|replay|record>HTTP recording mode for outbound Node SUT requestsoff
--recording-file=<path>JSON cassette path for HTTP recordings.spectest/cassette.json
--missing-recording-behavior=<fail|record|bypass>Behavior when replay can’t find a cassette entryfail
--openapi=<path>Path to an OpenAPI 3.0/3.1 document to load directlynone
--openapi-server=<url|index>Server URL or index to select from an OpenAPI document with multiple servers entriesnone
--coverage-reportPrint a per-operation OpenAPI contract coverage report after the runfalse
--coverage-report-file=<path>Write the coverage report to a file instead of stdoutnone
--negative-testsGenerate additional invalid-input (negative/fuzz) tests per OpenAPI operationfalse
--server-startup-timeout=<ms>Max time to wait for the SUT server to become ready before failing30000
--server-health-check-interval=<ms>Polling interval while waiting for the SUT server to become ready250
--dir=<path>Root directory of the project; anchors relative paths like testDir, openapi, recordingFilecurrent working directory
-h, --helpShow the help message and exit

Provide a file path without a flag to run just that suite. Options that accept a list of enum-like values (recording, runningServer, testOutput, missingRecordingBehavior) are validated whether they come from the CLI or from spectest.config.js.

See Test Suite and Test Case for details on the file format, and OpenAPI Testing, HTTP Recording, and Outbound Throttling for the larger features above.

outboundThrottle (rate-limiting the SUT server’s outbound calls) is config-file only — see Outbound Throttling.

Examples

# Run every suite discovered in testDir
npx spectest

# Only run a specific file
npx spectest auth.spectest.js

# Run with mobile user agent and write a snapshot
npx spectest --user-agent=chrome_android --snapshot=snap.json

# Load and run tests directly from an OpenAPI document
npx spectest --openapi ./openapi.yaml --base-url=https://api.example.com

# Print contract coverage after running an OpenAPI-backed suite
npx spectest --openapi ./openapi.yaml --coverage-report

# Generate negative/fuzz cases from the spec and report their coverage too
npx spectest --openapi ./openapi.yaml --negative-tests --coverage-report

generate openapi-tests

Scaffolds an editable .spectest.js file containing the same tests Spectest would generate in-memory from an OpenAPI document:

npx spectest generate openapi-tests --openapi <path> --output <dir> [--dir <projectRoot>] [--config <file>]

This is a convenience for suites that will grow real beforeSend/postTest logic by hand — everything it writes is already expressible via direct --openapi loading.