LogoCyanPrint

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-project
expected:
type: snapshot
value:
path: ./fixtures/expected/format-project
input: ./fixtures/input/unformatted
config:
formatter: prettier
installDeps: 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-deps
expected:
type: snapshot
value:
path: ./fixtures/expected/git-init-with-deps
input: ./fixtures/input/base-project
config:
installDeps: true
gitInit: true

Fields

FieldRequiredDescription
nameYesUnique test case identifier
expectedYesSnapshot path or inline expected value
inputYesPath to directory containing files to be modified
configNoRuntime 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:

  1. Copies all files from input to the output directory
  2. Runs your plugin against the output directory
  3. 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

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

Running Tests

# Run all tests
cyanprint test plugin .
# Run a specific test
cyanprint test plugin . --test format-project
# Run in parallel
cyanprint test plugin . --parallel 4
# Update snapshots after intentional changes
cyanprint test plugin . --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 plugin . --junit test-results.xml --disable-daemon-autostart

Next Steps