Skip to content
Edit this page

Test a template

Keep tests next to the template so changes to questions, conditionals, and generated files can be reviewed together. See the case reference for all declarations, and git tpl test for invocation and flags.

Start with a small case

Create tests/minimal.toml in the template repository:

[answers]
project_name = "example"

[expect]
files = ["README.md"]

[expect.contains]
"README.md" = "example"

Use question names and output paths from your own template, then run:

git tpl test minimal

Unanswered questions use template defaults, never prompts. Unknown answer names fail, so dropped or renamed questions cannot silently invalidate a case. Add explicit cases for important combinations rather than a combinatorial matrix.

Review snapshots

For full-output coverage, add snapshot = true at the case's top level:

git tpl test --write
git diff -- tests/__snapshots__
git tpl test

Review and commit the snapshot files with the template change. --write records expectations; it does not run assertions or commands. You can also edit expected payload files first, run the suite to see a failure, and then change the template to match without overwriting the desired expectation with --write.

Check behavior beyond file contents

Use context assertions for typed values and conditional absence. Use migration cases to verify upgrades from old template revisions, including project-local customizations. Use case commands when the generated project needs its own build checks. Those commands run in disposable test sandboxes; invoking test consents to running them.

Run in CI

Run git tpl test from the template checkout and use its exit status. For JSON consumers, distinguish a run failure from failed cases: ok reports whether the command ran, and summary.failed reports case failures. Authorize remote inheritance ancestors in CI's personal configuration before the suite starts.

Large suites can record timings and distribute cases across jobs with --shard. See sharding details for balancing and a matrix example.