How to gitignore snapshot folders?

Viewed 9146

I am starting to learn more about Jest and testing such as snapshot testing. The way I have my components in react configured is...

- src
  - components
    - Component1
      - index.js
      - __tests__
        - Component1.test.js
        - __snapshots__
  - Component2
      - index.js
      - __tests__
        - Component2.test.js
        - __snapshots__

and so on.

I'm wondering what would be the line to write in my .gitignore to ignore the __snapshots__ folder with this structure.

Currently I have this (which is wrong)

/src/components/*/__snapshots__/

Also, is it best to keep them in version control or to ignore them? I'd still like to know what I need to put in my gitignore, but would like to hear thoughts about this as well!

Thank you!

2 Answers

ignore the folder called snapshots anywhere, but not files with the same name

__snapshots__/

Since this has a “/” at the end only directories would be matched – removing it would also make the pattern catch files with the same name.

Related