LogoCyanPrint
ResolversHow-To Guides

Automated Testing

Set up snapshot-based automated testing for your resolvers

Automated Testing

The test command runs automated snapshot-based tests for your resolvers. Define test cases in test.cyan.yaml with multi-origin file inputs that simulate conflicts from layered templates, then compare the merged output against expected snapshots.

Quick Start

Create Test Configuration

Create test.cyan.yaml in your resolver project root:

tests:
- name: json-deep-merge
expected:
type: snapshot
value:
path: ./snapshots/json-deep-merge
config: {}
resolver_inputs:
- path: ./inputs/template-a
origin:
template: template-a
layer: 0
- path: ./inputs/template-b
origin:
template: template-b
layer: 1

Create Input Fixtures

Create directories for each template origin with conflicting files:

mkdir -p inputs/template-a inputs/template-b

Each directory should contain the files that template would produce, creating a conflict scenario for your resolver.

Run Tests

cyanprint test resolver .

On the first run, use --update-snapshots to generate initial expected output:

cyanprint test resolver . --update-snapshots

Understanding test.cyan.yaml

Each test case defines multi-origin inputs and expected merged output:

tests:
- name: three-way-merge
expected:
type: snapshot
value:
path: ./snapshots/three-way-merge
config:
strategy: deep
resolver_inputs:
- path: ./inputs/base
origin:
template: base-template
layer: 0
- path: ./inputs/feature-a
origin:
template: feature-a
layer: 1
- path: ./inputs/feature-b
origin:
template: feature-b
layer: 2

Fields

FieldRequiredDescription
nameYesUnique test case identifier
expectedYesSnapshot path or inline expected value
resolver_inputsYesList of file sets from different template origins
configNoRuntime configuration passed to the resolver

Resolver Inputs

Each entry in resolver_inputs represents files from a specific template:

FieldDescription
pathDirectory containing files from this template
origin.templateTemplate identifier this file set came from
origin.layerLayer index in composition order (0 = base, higher = overlay)

The layer ordering determines conflict resolution priority — higher layers overlay lower layers, matching how layered template composition works in production.

Project Structure

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

Running Tests

# Run all tests
cyanprint test resolver .
# Run a specific test
cyanprint test resolver . --test json-deep-merge
# Run in parallel
cyanprint test resolver . --parallel 4
# Update snapshots after intentional changes
cyanprint test resolver . --update-snapshots

When using --update-snapshots, resolver tests run sequentially regardless of the --parallel flag to ensure consistent snapshot generation.

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 resolver . --junit test-results.xml --disable-daemon-autostart

Next Steps