Automated Testing
Set up snapshot-based automated testing for your plugins
Automated Testing
The test command runs automated snapshot-based tests for your plugins. Define test cases in test.cyan.yaml with input fixtures and configuration, then compare output against expected snapshots.
Plugins modify files in-place. The test framework copies input files to the output directory, then runs your plugin against them. Your expected snapshots should reflect the final modified state.
Quick Start
Create Test Configuration
Create test.cyan.yaml in your plugin project root:
tests:- name: format-projectexpected:type: snapshotvalue:path: ./fixtures/expected/format-projectinput: ./fixtures/input/unformattedconfig:formatter: prettierinstallDeps: true
Create Input Fixtures
Create an input directory with files as they would exist before your plugin runs:
mkdir -p fixtures/input/unformatted
Add sample files representing the pre-plugin state (e.g., unformatted code, missing config files).
Run Tests
cyanprint test plugin .
On the first run, use --update-snapshots to generate initial expected output:
cyanprint test plugin . --update-snapshots
Understanding test.cyan.yaml
Each test case defines inputs and expected output for a plugin:
tests:- name: git-init-with-depsexpected:type: snapshotvalue:path: ./fixtures/expected/git-init-with-depsinput: ./fixtures/input/base-projectconfig:installDeps: truegitInit: true
Fields
| Field | Required | Description |
|---|---|---|
name | Yes | Unique test case identifier |
expected | Yes | Snapshot path or inline expected value |
input | Yes | Path to directory containing files to be modified |
config | No | Runtime configuration passed to the plugin |
Unlike processors, plugins do not use globs. Plugins receive the full output directory and modify files in-place.
In-Place Modification
The test framework:
- Copies all files from
inputto the output directory - Runs your plugin against the output directory
- Compares the modified output directory against
expected
This mirrors how plugins work in production — they receive a generated project directory and modify it.
Project Structure
Running Tests
# Run all testscyanprint test plugin .# Run a specific testcyanprint test plugin . --test format-project# Run in parallelcyanprint test plugin . --parallel 4# Update snapshots after intentional changescyanprint test plugin . --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 plugin . --junit test-results.xml --disable-daemon-autostart
Next Steps
- CLI Commands Reference — Full command options and flags
- Push to Registry — Publish your plugin