LogoCyanPrint
ProcessorsHow-To Guides

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-transform
expected:
type: snapshot
value:
path: ./snapshots/basic-transform
input: ./inputs/basic
config:
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-replacement
expected:
type: snapshot
value:
path: ./snapshots/variable-replacement
input: ./inputs/with-variables
config:
vars:
project_name: "my-app"
author: "developer"
globs:
- pattern: "**/*.ts"
type: Template
- pattern: "**/*.json"
type: Template

Fields

FieldRequiredDescription
nameYesUnique test case identifier
expectedYesSnapshot path or inline expected value
inputYesPath to directory containing input files
configNoRuntime configuration passed to the processor
globsNoFile 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:

index.ts
package.json
README.md

Project Structure

cyan.yaml
test.cyan.yaml
index.ts
Dockerfile
package.json

Running Tests

# Run all tests
cyanprint test processor .
# Run a specific test
cyanprint test processor . --test basic-transform
# Run in parallel
cyanprint test processor . --parallel 4
# Update snapshots after intentional changes
cyanprint test processor . --update-snapshots

Snapshot Comparison Rules

File TypeComparison Method
.json filesDeep comparison (field order ignored)
Other text filesExact string match (trailing whitespace trimmed)
Binary filesSkipped (reported but not compared)

CI/CD Integration

cyanprint test processor . --junit test-results.xml --disable-daemon-autostart

Next Steps