rules_jest
rules_jest copied to clipboard
[Bug]: snapshot update does not remove `.snap` files if file is renamed or stops producing snapshots
What happened?
There is a bug today where doing bazel run
will pass, but not remove the stale snapshot. If you run bazel test
, the snapshot will be marked as stale. To keep parity with jest, I would expect bazel run
to clean out the the source tree when a file is missing. Generated files test can do this today, so I would expect after a snapshot run to use a generated files test like write_source_files
to remove deleted files.
Version
Development (host) and target OS/architectures:
Output of bazel --version
: 6.2.0
Version of the Aspect rules, or other relevant rules from your
WORKSPACE
or MODULE.bazel
file:
0.19 - rules_jest
Language(s) and/or frameworks involved:
How to reproduce
`bazel run` a test target that produces a snapshot. Change the name of the file that produces the snapshot and run it again. It will pass. Run `bazel test` and you will see info that says there is an obsolete snapshot
Any other information?
- We know
jest_test
is passing-u
so that's good ✅ https://github.com/aspect-build/rules_jest/blob/main/jest/private/jest_test.bzl#L96 - rules_jest custom resolver under the hood https://github.com/aspect-build/rules_jest/blob/e3914b7c82190962f2e63a2daa76130924675630/jest/private/bazel_snapshot_resolver.cjs#L67
- default resolver from jest https://github.com/jestjs/jest/blob/aaf5315537e3ad02f93721e2e230df7bdcbccd43/packages/jest-snapshot/src/SnapshotResolver.ts#L59-L80
- Jest internally reads the snapshot resolver response using the custom functions via https://github.com/jestjs/jest/blob/main/packages/jest-snapshot/src/index.ts#L138 to determine what to cleanup