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: Add runtimeHooksPath options with onBeforeWriteToDiscPath in it #337

Merged
merged 7 commits into from
Nov 28, 2023

Conversation

Ayc0
Copy link
Contributor

@Ayc0 Ayc0 commented Jul 3, 2023

Description

Add a new top level option runtimeHooksPath that contains a potential path to a JS file.
This file can contain multiple hooks when diffSnapshot is called, like onBeforeWriteToDiscPath (to be able to inject EXIF data to PNGs without building this feature into this library).

The reason why I exposed that via a path to a JS file instead of exposing a function, is because diffSnapshot is sometimes called from a worker, and we cannot serialize properly functions.

For now there is only onBeforeWriteToDiscPath but I made that generic enough to be able to add more features to it in the future.

Motivation and Context

Fixes: #332

How Has This Been Tested?

I added unit tests for this feature

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My changes are in sync with the code style of this project.
  • There aren't any other open Pull Requests for the same issue/update.
  • These changes should be applied to a maintenance branch.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using Jest-Image-Snapshot?

It shouldn't impact them at all as long as they don't use this new feature

@Ayc0 Ayc0 requested a review from a team as a code owner July 3, 2023 12:38
code-forger
code-forger previously approved these changes Aug 17, 2023
@code-forger code-forger requested a review from a team August 17, 2023 08:57
@code-forger code-forger added the Contribution For contributions from outside the github team label Aug 17, 2023
@Ayc0
Copy link
Contributor Author

Ayc0 commented Sep 12, 2023

@code-forger what do you think about this new feature?

JAdshead
JAdshead previously approved these changes Nov 15, 2023
Copy link
Contributor

@JAdshead JAdshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long wait, this fell of the radar. Small comment but not going to block this.

} = options;

const writeFileSync = (pathToFile, content) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically i'd prefer moving this function out of diffImageToSnapshot and renaming to something like writeFileWithHooks and have it take runtimeHooksPath as a third argument. that way it more clearly differentiates the custom writeFileSync from fs.writeFileSync

as an example:

Suggested change
const writeFileSync = (pathToFile, content) => {
const writeFileWithHooks = (pathToFile, content, runtimeHooksPath) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't have time to do this modification right now, but I'll do it in the next few days!

Thanks for the review 🙇‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I'd need 5 arguments as testPath & currentTestName are also used inside of this writeFileSync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now updated
@JAdshead you can re-review if you want 👌

@Ayc0 Ayc0 dismissed stale reviews from JAdshead and Matthew-Mallimo via e3a7c86 November 16, 2023 21:40
@Ayc0 Ayc0 requested a review from JAdshead November 16, 2023 21:43
@Ayc0
Copy link
Contributor Author

Ayc0 commented Nov 16, 2023

FYI, due to bade294, the command npm run test:git-history seems to be failing:

image image

@Ayc0 Ayc0 force-pushed the Ayc0/on-before-save branch from 3817d04 to 15a46c7 Compare November 16, 2023 23:56
@Matthew-Mallimo Matthew-Mallimo merged commit 57741a2 into americanexpress:main Nov 28, 2023
10 checks passed
oneamexbot added a commit that referenced this pull request Nov 28, 2023
# [6.3.0](v6.2.0...v6.3.0) (2023-11-28)

### Features

* Add `runtimeHooksPath` options ([#337](#337)) ([57741a2](57741a2))
@oneamexbot
Copy link
Contributor

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Ayc0 Ayc0 deleted the Ayc0/on-before-save branch December 4, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution For contributions from outside the github team one-app-team-review-requested released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Expose onBeforeWriteToDisk hook (to manipulate EXIF data)
5 participants