Jest: Add comment to top of the snapshot file

Created on 4 Sep 2016  路  13Comments  路  Source: facebook/jest

Something to explain to people new to the concept that this is a generated file and perhaps a link that explains how snapshotting works :)

Help Wanted good first issue

Most helpful comment

I'd be happy to write a blogpost for the Jest blog sometime.

For the wording, how about:

// this file is generated, learn more: http://bit.ly/jest-snapshot

I'm sure that'd fit on one line on pretty much anyone's screen.

All 13 comments

I think that will be quite annoying if you have looads of snapshot files and all of them have the same header.

Hmmm... I was just thing something like:

// this is a generated file. Learn more: bit.ly/jest

Something simple so new people don't try to edit the file directly. I honestly don't see any problem with having the same comment in every file. I would expect people to naturally glaze over the top of the file anyway. I'd get used to it anyway :)

I think to do this we need two things:

  • A detailed blog post explaining what snapshot testing is and why it is useful (and when not to use it). @kentcdodds are you willing to help with that for the Jest blog?
  • A simple 3-5 word explanation so that the comment with URL fits into one line.

I'd be happy to write a blogpost for the Jest blog sometime.

For the wording, how about:

// this file is generated, learn more: http://bit.ly/jest-snapshot

I'm sure that'd fit on one line on pretty much anyone's screen.

@cpojer Is this still needed? I'd be happy to try and tackle this one if @kentcdodds don't want it.

Go ahead :-)

I'm gonna close this out due to inactivity. It hasn't really come up, so I'm inclined to keep snapshot files to the bare minimum.

I just move to jest 22, and I have a lot of .snap files, now I have to commit all of them again =/

@gabrielAnzaldo not sure what the issue is? Did it create new snap files? If so, can you open up a new issue?

@SimenB it adds at the top of the snap file the comment: '// this file is generated, learn more: http://bit.ly/jest-snapshot'.

This header is appearing in all of my snap files in the header, after running with the -u parameter.

snap-file

Yes, this is expected. So you commit all the snapshot files again and continue on.

@gabrielAnzaldo you should get a fair warning message in the console about this.

Was this page helpful?
0 / 5 - 0 ratings