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

Jest Snapshot Version Header #2853

Closed
cpojer opened this issue Feb 9, 2017 · 12 comments · Fixed by #2896
Closed

Jest Snapshot Version Header #2853

cpojer opened this issue Feb 9, 2017 · 12 comments · Fixed by #2896
Milestone

Comments

@cpojer
Copy link
Member

cpojer commented Feb 9, 2017

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 cpojer added this to the Jest 19 milestone Feb 9, 2017
@anilreddykatta
Copy link
Contributor

@cpojer You mean everytime snapshot updates.increment new version?

@cpojer
Copy link
Member Author

cpojer commented Feb 10, 2017

@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?

@anilreddykatta
Copy link
Contributor

@cpojer Yeah makes sense..so when we update snapshots next time..will the version number change?

@thymikee
Copy link
Collaborator

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

@anilreddykatta
Copy link
Contributor

@thymikee Thanks 👍

@kentaromiura
Copy link
Contributor

can we add something like

exports['Schema Version'] = 1;

Instead of a comment? (as it's easier to get it for checks later)

@thymikee
Copy link
Collaborator

What about naming collision, when someone names the snapshot the same way?

@cpojer
Copy link
Member Author

cpojer commented Feb 10, 2017 via email

@thymikee
Copy link
Collaborator

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?

@cpojer
Copy link
Member Author

cpojer commented Feb 11, 2017

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.

@thymikee
Copy link
Collaborator

BTW, I'll be working on this tomorrow, but if anyone has time to deal with it today, don't hesitate!

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants