Generated snapshot tests across multiple configurations of your blueprint are supported.
Blueprints support snapshot testing
To enable snapshot testing
-
In the
.projenrc.ts
file, update the input object to ProjenBlueprint with the files you want to snapshot. For example:{ .... blueprintSnapshotConfiguration: { snapshotGlobs: ['**', '!environments/**', '!aws-account-to-environment/**'], }, }
-
Resynthesize the blueprint to create TypeScript files in your blueprint project. Don’t edit the source files since they’re maintained and regenerated by Projen. Use the following command:
yarn projen
-
Navigate to the
src/snapshot-configurations
directory to view thedefault-config.json
file with an empty object. Update or replace the file with one or more of your own test configurations. Each test configuration is then merged with the project’sdefaults.json
file, synthesized, and compared to snapshots when testing. Use the following command to test:yarn test
The first time you use a test command, the following message is displayed:
Snapshot Summary › NN snapshots written from 1 test suite
. Subsequent test runs verify that the synthesized output hasn’t changed from the snapshots and display the following message:Snapshots: NN passed, NN total
.If you intentionally change your blueprint to produce a different output, then run the following command to update the reference snapshots:
yarn test:update
Snapshots expect synthesized outputs to be constant between each run. If your blueprint generates
files that vary, you must exclude those files from the snapshot testing. Update the
blueprintSnapshotConfiguration
object of your ProjenBluerpint
input object to
add the snapshotGlobs
property. The snapshotGlobs
property is an array of
globs
Note
There is a default list of globs. If you specify your own list, you may need to explicitly bring back the default entries.