Automated Testing
Set up snapshot-based automated testing for your processors
Automated Testing
The test command runs automated snapshot-based tests for your processors. Define test cases in test.cyan.yaml with input fixtures, configuration, and glob patterns, then compare output against expected snapshots.
Unlike templates, processors do not support test init. You need to create test.cyan.yaml manually.
Quick Start
Create Test Configuration
Create test.cyan.yaml in your processor project root:
tests:- name: basic-transformexpected:type: snapshotvalue:path: ./snapshots/basic-transforminput: ./inputs/basicconfig:vars:name: "World"globs:- pattern: "**/*.ts"type: Template
Create Input Fixtures
Create an input directory with files your processor will receive:
mkdir -p inputs/basic
Add sample files that represent what a template would produce before processing.
Run Tests
cyanprint test processor .
On the first run, use --update-snapshots to generate the initial expected output:
cyanprint test processor . --update-snapshots
Understanding test.cyan.yaml
Each test case defines inputs and expected output for a processor:
tests:- name: variable-replacementexpected:type: snapshotvalue:path: ./snapshots/variable-replacementinput: ./inputs/with-variablesconfig:vars:project_name: "my-app"author: "developer"globs:- pattern: "**/*.ts"type: Template- pattern: "**/*.json"type: Template
Fields
| Field | Required | Description |
|---|---|---|
name | Yes | Unique test case identifier |
expected | Yes | Snapshot path or inline expected value |
input | Yes | Path to directory containing input files |
config | No | Runtime configuration passed to the processor |
globs | No | File glob patterns with type (matching template glob configuration) |
Input Directory
The input directory contains files as they would be received from a template before processing. Structure it to match your processor's expected input:
Project Structure
Running Tests
# Run all testscyanprint test processor .# Run a specific testcyanprint test processor . --test basic-transform# Run in parallelcyanprint test processor . --parallel 4# Update snapshots after intentional changescyanprint test processor . --update-snapshots
Snapshot Comparison Rules
| File Type | Comparison Method |
|---|---|
.json files | Deep comparison (field order ignored) |
| Other text files | Exact string match (trailing whitespace trimmed) |
| Binary files | Skipped (reported but not compared) |
CI/CD Integration
cyanprint test processor . --junit test-results.xml --disable-daemon-autostart
Next Steps
- CLI Commands Reference — Full command options and flags
- Push to Registry — Publish your processor