-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Splitting Snapshot Files #2676
Comments
Another option is to make |
What you can do right now, it's changing your test generator to make a single test file per expectation.
where This way you can keep the |
This relies on all your tests having names which are valid file paths, or doing some sort of semi-destructive transform on them, and that’s not really the granularity I want, either!
This is more viable, but not exactly the nicest way to approach this. It’s bad enough to write complicated filesystem code just to write tests, so writing such a thing to make my test snapshots come out in a nice format seems like bad news! Likewise, having to create/delete files all the time feels like a bad move for SSD longevity 😉. |
I'm heavily against this because it will make tracking of snapshot files harder and would require more static analysis. There are two questions you should ask yourself:
Answering one or both of these questions should lead to smaller snapshot files. Especially the second one is essentially a "user-land implementation" of your feature that comes at no additional complexity for Jest. Also, SSDs don't suffer the longevity issues any more, so that isn't really a concern here. |
It’s less the big and more that I don’t necessarily need to store them repeatedly - there’s no way for me to declare, as it stands, “these combinations of situations should all map to this result,” which is what leads to the large snapshot file sizes.
I mean, technically yes, but in the case of the example, what you end up with is three files which test slight variations on the same thing, and worse, would actually serve to make writing combinations of those cases more difficult. |
I feel like the correct answer here would then be to write a diff engine that will make it so that your snapshot will only capture the difference between the items, rather than all the content. @xixixao actually just asked about this at FB last week. |
I remember @pedrottimark was discussing somewhere about |
I will eventually catch up to @pedrottimark's awesome issues where he discusses these things, mostly with himself (sorry I haven't been able to keep up, please keep posting issues. I see them :D ) |
Having an option to store each snapshot to a separate file would be super useful for cases like NextJs pages snapshots where you can simply require all files from pages/ folder. At this moment I have a snapshot file of ~2Mb and it's even not a half of all pages. It looks like continuing adding snapshots this way isn't scalable. Splitting the single simple test with looping over pages-files into manually or auto-generated list of test files looks overcomplicated as well |
another use case: solved by jest-specific-snapshot - thx @armano2 : ) |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
Request a feature
What is the current behavior?
Currently, when using snapshots, a snapshot file is created per test file. In cases where test cases are generated, the snapshot files can become thousands of lines, which makes them unwieldy.
What is the expected behavior?
It would be useful to be able to break up these large, complex test files. I’d propose either some sort of hook in the Jest API;
Should result in
__snapshots__
containing;Or the ability to specify the maximum size (actual interpretation of “size” open to opinions - bytes? lines? results?) of any given snapshot file.
For cases where Jest is used for integration testing or to test several different configurations within something complex, this would allow for nicer output, especially when testing large chunks of React component output!
The text was updated successfully, but these errors were encountered: