Filtering
Prism provides powerful filtering capabilities to run specific subsets of your test suite.
Name Filter
Section titled “Name Filter”Filter tests by name using regex patterns:
vendor/bin/prism test --filter "string.*"Matches test descriptions against the provided regex pattern.
Examples
Section titled “Examples”# Run only string-related testsvendor/bin/prism test --filter "^string"
# Run tests containing "validation"vendor/bin/prism test --filter "validation"
# Run tests matching multiple patternsvendor/bin/prism test --filter "string|number|boolean"Path Filter
Section titled “Path Filter”Filter test files by path using glob patterns:
vendor/bin/prism test --path-filter "tests/required/**/*.json"Only runs tests from files matching the glob pattern.
Examples
Section titled “Examples”# Run tests only from the 'required' directoryvendor/bin/prism test --path-filter "**/required/**"
# Run tests from specific subdirectoriesvendor/bin/prism test --path-filter "tests/{draft7,draft2020}/**"
# Run only top-level test filesvendor/bin/prism test --path-filter "tests/*.json"Exclusion Filter
Section titled “Exclusion Filter”Exclude tests by name using regex patterns:
vendor/bin/prism test --exclude "optional|deprecated"Excludes tests whose descriptions match the provided regex.
Examples
Section titled “Examples”# Exclude optional testsvendor/bin/prism test --exclude "optional"
# Exclude multiple patternsvendor/bin/prism test --exclude "optional|edge-case|experimental"
# Exclude tests with specific keywordsvendor/bin/prism test --exclude "slow|flaky"Tag Filter
Section titled “Tag Filter”Filter tests by tags defined in test files:
vendor/bin/prism test --tag "required"Only runs tests that have the specified tag.
Tag Definition
Section titled “Tag Definition”Define tags in your test files:
{ "description": "String validation", "schema": { "type": "string" }, "tests": [ { "description": "valid string", "data": "hello", "valid": true, "tags": ["string", "required", "basic"] }, { "description": "edge case", "data": "", "valid": true, "tags": ["string", "edge-case"] } ]}Examples
Section titled “Examples”# Run only required testsvendor/bin/prism test --tag "required"
# Run edge case testsvendor/bin/prism test --tag "edge-case"
# Run regression testsvendor/bin/prism test --tag "regression"Draft Filter
Section titled “Draft Filter”When using multiple validators, filter by validator name:
vendor/bin/prism test --draft "draft-7"Runs tests only for the specified draft/validator.
Examples
Section titled “Examples”# Test only Draft 7 implementationvendor/bin/prism test --draft "draft-7"
# Test only Draft 2020-12 implementationvendor/bin/prism test --draft "draft-2020-12"Combining Filters
Section titled “Combining Filters”All filters can be combined for precise test selection:
vendor/bin/prism test \ --filter "string" \ --tag "required" \ --exclude "optional" \ --path-filter "**/core/**"This runs tests that:
- Match “string” in the name
- Have the “required” tag
- Don’t match “optional” in the name
- Are in files under a “core” directory
Incremental Mode
Section titled “Incremental Mode”Run only tests from files that changed since the last run:
vendor/bin/prism test --incrementalPrism tracks file modification times and only runs tests from changed files.
Use Cases
Section titled “Use Cases”- Fast iteration: Only run tests affected by recent changes
- CI optimization: Skip unchanged tests in continuous integration
- Development workflow: Quickly verify local changes
How It Works
Section titled “How It Works”- First run: All tests execute, file timestamps cached
- Subsequent runs: Only changed files tested
- Cache location:
.prism/incremental-cache.json
Example Workflow
Section titled “Example Workflow”# Initial run - all testsvendor/bin/prism test --incremental
# Make changes to test filesvim tests/validation/strings.json
# Only changed tests runvendor/bin/prism test --incrementalInteractive Filter Configuration
Section titled “Interactive Filter Configuration”Use interactive mode to configure filters through a menu:
vendor/bin/prism test --interactiveInteractive mode provides:
- Name filter configuration
- Tag selection
- Parallel worker configuration
- Real-time filter preview
- Test execution with configured filters
Interactive Menu
Section titled “Interactive Menu”Current Configuration: Filter: <none> Tag: <none> Parallel: 1 worker(s)
Select action: > Run tests with current configuration Set name filter (regex) Set tag filter Configure parallel workers Clear all filters ExitPerformance Tips
Section titled “Performance Tips”Optimize Filter Performance
Section titled “Optimize Filter Performance”-
Use path filters for large test suites
Terminal window vendor/bin/prism test --path-filter "tests/critical/**" -
Combine with parallel execution
Terminal window vendor/bin/prism test --filter "api" --parallel 4 -
Use incremental mode during development
Terminal window vendor/bin/prism test --incremental --watch
Filter Precedence
Section titled “Filter Precedence”Filters are applied in this order:
- Path filter - Files are filtered first
- File-level filters -
shouldIncludeFile()in config - Test execution - Tests run from filtered files
- Name filter - Test names filtered
- Tag filter - Tests filtered by tags
- Exclusion filter - Matching tests excluded
Next Steps
Section titled “Next Steps”- Explore performance features
- Learn about advanced features
- See output formats