americanexpress / jest-image-snapshot

✨ Jest matcher for image comparisons. Most commonly used for visual regression testing.
Apache License 2.0
3.83k stars 198 forks source link

Could customSnapshotDir be a callback? #347

Open velvet-dream opened 8 months ago

velvet-dream commented 8 months ago

As suggested here in this issue https://github.com/americanexpress/jest-image-snapshot/issues/62

It would be really useful to have customSnapshotsDir specified as function, in order to have much more flexibility over the way snapshots are stored, and make it possible to generate path on the fly depending on testPath, etc.

{ customSnapshotsDir: ({currentTestName, testPath}) => buildCustomSnapshotDirOnTheFly(currentTestName, testPath) }

In my usecase, we have our own framework with our React components. There are many components, and I would like to get all the snapshots stored in the same directory, with a structure identical to that of the framework. Something that would look like this:

root/
├─ snapshots/
│  ├─ inputs/
│  │  ├─ button/
│  │  │  ├─ button-snapshot.png
│  │  ├─ inputNumber/
│  │  │  ├─ inputNumber-snapshot.png

A commit was submitted a few years ago : https://github.com/goverdhan07/jest-image-snapshot/commit/0277834beaef81107759f9ca84a4f84a50d74735

What do you think?