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

Support non json #109

Open
JTeeuwissen opened this issue Feb 2, 2024 · 5 comments
Open

Support non json #109

JTeeuwissen opened this issue Feb 2, 2024 · 5 comments
Labels
enhancement New feature or request waiting for interest Waiting for more interest from the community

Comments

@JTeeuwissen
Copy link

Is your feature request related to a problem? Please describe.
The current snapshot functionality always uses json to store the snapshot data. When the string is not valid json, it is stored as a json string. This conversion and escaping makes it difficult to read larger chunks of e.g. serialized generated code.

Describe the solution you'd like
Id like a new api to snapshot strings (and potentially other objects) straight to a file, without any json conversion.

Solutions like Verify support this scenario, but i much prefer the snapper workflow.

@JTeeuwissen JTeeuwissen added the enhancement New feature or request label Feb 2, 2024
@theramis
Copy link
Owner

theramis commented Feb 11, 2024

Thanks for the suggestion!

Hmm this is something Snapper V1 used to support but it was much harder to maintain and I didn't see many users wanting that functionality.

Since then I've added Snapshots per class and Child snapshots as features which is something that really only works with json or some form of structured format.

These features would break if we wanted to store without json conversions.

I think there are two options for next steps

  1. Snapper allows customer serialisers for json conversion. You could have a look at implementing one that makes your json conversions easier to read?
  2. If there is enough interest by others I could investigate if Snapper could provide this but with limited functionality.

@theramis theramis added the waiting for interest Waiting for more interest from the community label Feb 11, 2024
@JTeeuwissen
Copy link
Author

The second option would match my use case. Child snapshots could be implemented using an extended file name. I could investigate an implementation, if this is something you feel like fits the library.

@torstenholva
Copy link

torstenholva commented Apr 4, 2024

There is a problem with comparing datetimes in DevOps. When making the snapper json files locally (in another time zone) and then running the tests in DevOps, the time zone might change for the datetime and the test fails.

2020-09-10T00:00:00+03:00 changes to 2020-09-09T21:00:00+00:00

If the json file would be replaced with a snap file (for instance), would the datetime value be compared as a string?

@JTeeuwissen
Copy link
Author

Probably yes,
But I think that is the wrong solution for your problem. Instead, could the test / sut be updated to have a Invariant timezone? Or use a date time without a time zone?

@torstenholva
Copy link

Yes, the latter was our solution to the problem. Will investigate if the first is an option in our context.
And thanks for a great tool, by the way! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting for interest Waiting for more interest from the community
Projects
None yet
Development

No branches or pull requests

3 participants