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

More jest integration #10

Closed
avocadowastaken opened this issue Aug 10, 2017 · 5 comments
Closed

More jest integration #10

avocadowastaken opened this issue Aug 10, 2017 · 5 comments

Comments

@avocadowastaken
Copy link
Contributor

First of all I would like to thank you for your work!
It allowed me to decreased snapshot file size from 10k lines to 1.3k!

Add custom matcher

e.g. https://github.com/americanexpress/jest-image-snapshot#usage
See https://facebook.github.io/jest/docs/expect.html#expectextendmatchers
Usage:

expect(nextState).toMatchDiffSnapshot(prevState, { contextLines: 2 })

Add snapshot serializer based on input type

e.g. https://github.com/prettier/prettier/blob/master/tests_config/raw-serializer.js

Current output for object diffs is too noisy, so I had do implement custom serializer in my project, and now output changed from:

 Object {
   \\"bail\\": false,
   \\"context\\": \\".\\",
   \\"devServer\\": Object {
     \\"disableHostCheck\\": true,
-    \\"host\\": \\"localhost\\",
+    \\"host\\": \\"local.host\\",
     \\"hotOnly\\": true,
     \\"inline\\": true,
     \\"noInfo\\": true,
     \\"overlay\\": Object {
       \\"errors\\": true,
       \\"warnings\\": true,
     },
     \\"port\\": 3000,

To:

 Object {
   "bail": false,
   "context": ".",
   "devServer": Object {
     "disableHostCheck": true,
-    "host": "localhost",
+    "host": "local.host",
     "hotOnly": true,
     "inline": true,
     "noInfo": true,
     "overlay": Object {
       "errors": true,
       "warnings": true,
     },
     "port": 3000,

I would love to add PR with this changes.

@thymikee
Copy link
Member

Hey! Thanks for posting. And I'd love to review the PR :)
cc @ferrannp

@thymikee
Copy link
Member

As a side note, I forgot about custom matcher and serializer but this seems like a fine way to go.
Instead I thought about fixing the issue upstream in Jest – here's a proposal jestjs/jest#4183.

@avocadowastaken
Copy link
Contributor Author

@thymikee should I close this and wait for jestjs/jest#4183 or proceed to second step?

@thymikee
Copy link
Member

I'd go with snapshot serializer now, and switch to jestjs/jest#4183 when it's merged and new Jest is released. You can mimic the output I guess.

@thymikee
Copy link
Member

Fixed with #12

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

2 participants