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 for JSON Snapshots #82

Open
sazzer opened this issue Sep 15, 2022 · 1 comment
Open

Support for JSON Snapshots #82

sazzer opened this issue Sep 15, 2022 · 1 comment

Comments

@sazzer
Copy link

sazzer commented Sep 15, 2022

Currently the diffing tool used by Cupaloy treats strings as just a sequence of characters. Which is reasonable, but limited.

In particular, it would be fantastic if there were a way to tell it to treat the two strings as JSON. Which would mean:

  • Whitespace is ignored
  • Object keys are unordered

That way, any changes to the output that are changes to the raw string but are not meaningful changes to the JSON structure are ignored and will not cause the tests to fail.

In particular, I've had an issue where VSCode auto-formats the JSON within a snapshot file when I'm making changes to it, which then means that everything breaks. Often it actually means it's quicker to delete the file and regenerate it rather than just fixing up one value that's changed because of a code change.

@sazzer
Copy link
Author

sazzer commented Sep 15, 2022

In reality this would probably just mean changing:

	if snapshot == prevSnapshot || takeV1Snapshot(i...) == prevSnapshot {

in cupaloy.go to use a configured diffing function instead of ==. Users can then provide their own means to compare values - e.g. github.com/kinbiko/jsonassert, but maybe even much more complicated things for some cases like image snapshots or whatever.

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

No branches or pull requests

1 participant