Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Expose onBeforeWriteToDisk hook (to manipulate EXIF data) #332

Closed
Ayc0 opened this issue May 31, 2023 · 4 comments · Fixed by #337
Closed

[Feature request] Expose onBeforeWriteToDisk hook (to manipulate EXIF data) #332

Ayc0 opened this issue May 31, 2023 · 4 comments · Fixed by #337

Comments

@Ayc0
Copy link
Contributor

Ayc0 commented May 31, 2023

At the moment, any test can generate any snapshot, and it's really hard to be able to find which test generated which image (as we can provide custom paths for the images, we cannot just rely on the path of the images, and also if we have 2 tests files in the same folder, images can be put in the same folder).

We could use EXIF data in images to store metadata in them (and we could also add the possibility in .toMatchImageSnapshot() to provide extra EXIF data if we want too), like the test suite (with the describe / it), the test path etc.

@Ayc0 Ayc0 changed the title [Feature request] Store in EXIF data path to initial test [Feature request] Store in EXIF data tests metadata May 31, 2023
@Ayc0
Copy link
Contributor Author

Ayc0 commented Jun 12, 2023

We can use https://www.npmjs.com/package/node-exiftool to help with this (this library can read & write exif)

Edit: this library requires another one to be installed top level. So this is a no go.

What about https://github.com/hometlt/png-metadata or https://github.com/kujirahand/node-png-metadata? it's not really about exif data but other kind of metadata. It only works for PNG but jest-image-snapshot also only supports them

@Ayc0
Copy link
Contributor Author

Ayc0 commented Jun 21, 2023

If that's something we want to do, I can propose a PR

@Ayc0
Copy link
Contributor Author

Ayc0 commented Jun 27, 2023

I look a bit into it, and manipulate EXIF can be tricky: there is plenty we can do and I don't think there is much we'd like to do from the jest-image-snapshot point of view.

One thing we could do is expose a hook for just before writing a file to the FS:

type OnBeforeWriteToDisk = (arguments: {
  buffer: Buffer; testPath: string; destination: string; /* others */
}) => Buffer

So that people could be free to do what they want with it, and while keeping the full control on how to write to disk

@Ayc0 Ayc0 changed the title [Feature request] Store in EXIF data tests metadata [Feature request] Expose onBeforeWriteToDisk hook (to manipulate EXIF data) Jun 27, 2023
@Ayc0
Copy link
Contributor Author

Ayc0 commented Jul 3, 2023

I opened #337 to solve this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant