`projen test` updates snapshots by default
See original GitHub issueGiven a TypeScriptAppProject
, yarn test
does the following:
$ npx projen test
....
š¤ test | jest --passWithNoTests --all --updateSnapshot
The --updateSnapshot
is dangerous: if I run this in CI, yarn test
will not actually validate my snapshots, but happily update them in place even if my tests should by all rights have failed.
The answer is not āanti-tamper protectionā: that will tell me that files have changed, it will not give me the nice error message and diff that jest
would have given me if the snapshot test was allowed to fail in the first place. Plus, you canāt assume that the tests will always be run with the synthesized GitHub workflow that includes anti-tamper protection: it might equally well run in a CodePipeline/CodeBuild setup, and that job might not even have access to the git repo to compare for any diffs.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:14 (8 by maintainers)
@jtnz
Thanks for your suggestion, but unfortunately, this did not work for us. In the latest Version of projen, the
step.exec
is read only.We used your suggestion and migrated it to:
Additionally for others trying this out, please add it before
project.synth();
šHereās a proposal - let me know if this makes sense.
Current way things work:
test
task which intentionally updates files. Thereās also atest:update
task (in JS-based project types), but it currently does the same thing.mutableBuild
option determines whether to add a GitHub workflow step to push snapshot changes / eslint fixes back to your PR as a new commit (if youāre not using GitHub, it does nothing).Proposed way things should work:
test
task does not intentionally update files.test:update
task does intentionally update files (by passing the appropriate flags tojest
andeslint
etc).mutableBuild
option is split intomutableBuildTask
andmutableBuildWorkflow
.mutableBuildTask
will determine whether the defaultbuild
task runstest
ortest:update
(irrespective of whether youāre running them locally or in CI/CD).mutableBuildWorkflow
will do whatmutableBuild
did, but will also do nothing ifmutableBuildTask
is false.In the future,
mutableBuildTask: false
should also cause runningnpx projen
in CICD to fail immediately if it detects any configuration files that need to be updated, but this requires some more technical changes to projenās synthesis engine.