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

(feat) add inline snapshot #59

Open
lukeapage opened this issue Sep 7, 2019 · 3 comments
Open

(feat) add inline snapshot #59

lukeapage opened this issue Sep 7, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@lukeapage
Copy link
Contributor

Having the assertion separate from the test makes it less likely to be reviewed and makes it harder to align assertion value and test.

Describe the solution you'd like
To implement toMatchInlineSnapshot like jest.

Jest implementation: jestjs/jest@d3a6a74#diff-5d8368ae467702f37535e03f31a2ed96

It seems doable from a cursory look. I would follow the jest approach, requiring prettier if it’s used. I’m interested in implementing this myself, just raising this in case you have objections or suggestions.

@lukeapage lukeapage added the enhancement New feature or request label Sep 7, 2019
@lukeapage
Copy link
Contributor Author

jest captures the stack on calling toMatchInlineSnapshot and then matches up the ast based on the callsite column and line.

There are some challenges doing this with cypress:

  1. the call is async. We'd need to monket patch cypress so the stack trace comes from the sync part of the call rather than being called once async dependencies are fetched. This could be worked around I think, maybe a bit like this: better stack trace/ sourceMaps cypress-io/cypress#881 (comment)
  2. the source is transformed. Unfortunately theres no way to get the sourcemapping right now, so we are dependent on this issue being resolved first: Utilize source maps for error improvements cypress-io/cypress#4041

so, I think a workable approach would be to use the test title and the order of the calls to determine the right call to make. This is more limiting, but in practice I can't think of any problems - for instance if you have a forEach around the test and dynamically create the test - this currently works in jest, but it opts out if the same call site is used more than twice - so in practice it only works if the dynamic test name is created only once. The same for abstracted functions - they work but only if called once. So I do not think the limitations are too bad - it would work for me.

@sidharthv96
Copy link

Now that cypress-io/cypress#4041 is merged, is it technically possible to implement this?

@jaredatdannyronsrescue
Copy link

This would be a long awaited feature for us.

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

No branches or pull requests

4 participants