aspect-build / aspect-build/rules_jest
[Bug]: snapshot update does not remove `.snap` files if file is renamed or stops producing snapshots
- Dominant language
- Starlark
- Stars
- 24
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
### 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
```shell
`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?
1. 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
2. rules_jest custom resolver under the hood https://github.com/aspect-build/rules_jest/blob/e3914b7c82190962f2e63a2daa76130924675630/jest/private/bazel_snapshot_resolver.cjs#L67
3. default resolver from jest https://github.com/jestjs/jest/blob/aaf5315537e3ad02f93721e2e230df7bdcbccd43/packages/jest-snapshot/src/SnapshotResolver.ts#L59-L80
4. 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
Contributor guide
Research direction
Reproduce the rename or no-longer-producing-snapshots case with `bazel run`, then compare it with `bazel test`. Read `jest/private/jest_test.bzl` and `jest/private/bazel_snapshot_resolver.cjs`, followed by Jest's `SnapshotResolver.ts` and `jest-snapshot/src/index.ts`. Done means `bazel run` removes stale `.snap` files from the source tree while retaining the expected snapshot behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100