-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Snapshot feature will modify existing snapshots without passing --update-snapshots
flag
#1218
Comments
Thank you for a detailed bug report, I just reproduced it and looking into it. |
I think the problem lies with If I remove the |
Hm yes, this makes the issue gone indeed. I've been debugging this issue inside jest-snapshot, and the problem lies in saving snapshot file. For some reason, on the second run, it reserializes/reencodes the last item in the snapshot. |
I tried to see if for some reason the macro was causing the problem, and broke out the tests into long form, and it still produced the same result. Then, I wanted to check to see if it was You can see the jest branch here if needed: https://github.com/wyze/ava-snapshot-issue/tree/jest |
Found this issue, seems to be related, from what I've observed - jestjs/jest#2478. If you keep a snapshot open in the editor, you'll see how it gets modified on the 2nd run. |
Cool, thanks for digging in. It looks like this was fixed with jestjs/jest#2482 and we just need to wait for the next release to be cut. |
Just opened #1223 - a dead-simple snapshot implementation, I hope it will eliminate such bugs and you can use |
By the way, I would really appreciate it, if you could try this branch on your project and see if it solves existing/introduces new issues, if you've got some free time. No worries if not, though! |
Looks great @vadimdemedes, thanks! I pushed a new branch, wyze/ava-snapshot-issue#ava-1223, in the repo that works without issue now. I've also tested this in my real project and it works as well. But it does create snapshots, even if there is no snapshot assertion in that test file. So, in the project with more tests, there are |
This is a good catch, will fix. Thank you a lot for taking the time to test it out! |
Is there any chance of getting a 'quick fix' for this while y'all pull together #1223 ? The current state makes snapshots unusable. Is the issue that |
@pho3nixf1re It's merged, but not released. |
Actually, the
We're always saving the snapshot. This should be fine, because However, as it turns out we're saving snapshots from inside the Instead we should save the snapshots after all tests in the test file have completed, but before the worker exits. |
The reason we should save even without |
Actually, we should not save snapshot if we are running within CI server. |
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
* Make the Runner manage the snapshot state. Thread an accessor to the `t.snapshot()` assertion. * Save snapshots when runner has finished. Fixes #1218. * Use jest-snapshot directly, without serializing values. Use jest-diff to generate the diff if the snapshot doesn't match. This does mean the output is not colored and has other subtle differences with how other assertions format values, but that's OK for now. Fixes #1220, #1254. * Pin jest-snapshot and jest-diff versions. This isn't ideal but we're using private APIs and making other assumptions, so I'm not comfortable with using a loose SemVer range.
Description
The results with snapshots are inconsistent when ran multiple times with no code changes. I've provided a repository with an example below.
Upon cloning the repo and running
npm test
it will pass the tests but leave the snapshots modified (See output of 2nd pass below). If you run tests again, it will throw an error (See 3rd pass output below).For what it's worth, I was using the
master
branch after the snapshot feature first landed and had no issues. It seems like the bug was introduced when the magic assert feature was introduced. I even tried deleting the snapshot folder and getting a fresh run, but it still produces the same results.Error Message & Stack Trace
Config
Copy the relevant section from
package.json
:Command-Line Arguments
Copy your npm build scripts or the
ava
command used:Relevant Links
See reproducable repo here: https://github.com/wyze/ava-snapshot-issue
Environment
Node.js v7.1.0
darwin 16.1.0
npm 4.0.3
AVA 0.18
The text was updated successfully, but these errors were encountered: