We discussed adding a header like:
// Jest Snapshot v1
and then validate Jest and throw if the snapshot version doesn't match, like:
Error: The snapshot file associated with this project is for version 1 but Jest 25 expects version 2.
@cpojer You mean everytime snapshot updates.increment new version?
@anilreddykatta no, it's a version that we define in jest-snapshot, like:
const SNAPSHOT_VERSION = '1';
// later:
writeSnapshot() {
const content = `// Jest Snapshot v${SNAPSHOT_VERSION}, <short url description>`
}
// readSnapshot
const content = readSnapshot();
if (snapshotVersionFromFirstLine < SNAPSHOT_VERSION) {
throw new Error('update your snapshots!');
}
does that make sense?
@cpojer Yeah makes sense..so when we update snapshots next time..will the version number change?
Yes. This is just to let you know, that there's a change in snapshot formatting, which you should just update, because it breaks your tests
@thymikee Thanks š
can we add something like
exports['Schema Version'] = 1;
Instead of a comment? (as it's easier to get it for checks later)
What about naming collision, when someone names the snapshot the same way?
I think a comment is way more correct for this use case.
From: MichaÅ PierzchaÅa notifications@github.com
Sent: Friday, February 10, 2017 6:20:32 PM
To: facebook/jest
Cc: Christoph Pojer; Mention
Subject: Re: [facebook/jest] Jest Snapshot Version Header (#2853)
What about naming collision, when someone names the snapshot the same way?
ā
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/facebook/jest/issues/2853#issuecomment-279023472, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAA0KAJACWu5BsHNvPbHRfhiM8ZUZYT9ks5rbKpwgaJpZM4L8fDc.
Maybe for first version we should not throw an error? We could just save the information about the version 1 in Jest 19 and error on future changes, what do you think?
It should definitely throw an error in the first version. If Jest doesn't detect this header, throw -> it means you are pre Jest 19 and the snapshot must be updated.
BTW, I'll be working on this tomorrow, but if anyone has time to deal with it today, don't hesitate!
Most helpful comment
I think a comment is way more correct for this use case.
From: MichaÅ PierzchaÅa notifications@github.com
Sent: Friday, February 10, 2017 6:20:32 PM
To: facebook/jest
Cc: Christoph Pojer; Mention
Subject: Re: [facebook/jest] Jest Snapshot Version Header (#2853)
What about naming collision, when someone names the snapshot the same way?
ā
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/facebook/jest/issues/2853#issuecomment-279023472, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAA0KAJACWu5BsHNvPbHRfhiM8ZUZYT9ks5rbKpwgaJpZM4L8fDc.