Separate implementation of jest-snapshot #2497
Do you want to request a feature or report a bug?
Solution for Reporting
Solution for Deleting?
When it comes to tests being deleted from a file (so index.test.js changes but the snapshot of it doesn't), it might be sufficient if the state checks at the end of the process that the tests it has run are exactly equal to the snapshots that exist, deleting redundant snapshots. That would mean however, that at some point the implementation needs to nudge the state telling it we have finished running the relevant test file.
Deleting redundant files pose a similar issue, only on higher level. When all tests have finished, we need to check that there are no deleted snapshot test file lying around, throughout the whole project codebase.
Another solution would be to "scan" the test suite before running it and resolving these issues before the tests start running.
I'm sure jest has sorted it out somehow already. Could you briefly explain to me how/where the deletion happens? Might be only a case of moving things around a bit.
Solution for Interactive Watch
For deleting and keeping the state that's what we do in Jest, and it's not as straightforward because there are exceptions, I remember @dmitriiabramov added some code to catch when one runs a focused test (eg a real case scenario might be while debugging an issue or writing a brand new test) and in that case you don't want to delete all the snapshots.
Edit: I think this is the commit I was thinking about 26478b5
We spent a ton of time at Facebook to get the UX for snapshot testing just right. I think we did well, even though I think we are still at the beginning – there is so much more we can do. I believe it is critical to make the snapshot feature more generic so that bringing snapshots to other frameworks will also result in a great experience. My main worry of adopting jest-snapshot in other projects has been that the integration may not be as great as in Jest and it would steer people away from using this assertion for the wrong reasons. Thanks @lithin for bringing this up, here are my thoughts:
There are also a ton more things we'd like to add to the snapshot feature, as well as an interactive update mode but that should be discussed in a separate issue.