简体   繁体   中英

How to gitignore snapshot folders?

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!

I had the same question and ended up finding this post here. However, Jest documentation states that:

all snapshot files should be committed alongside the modules they are covering and their tests

Hope this helps others as has helped me.

Source: https://jestjs.io/docs/en/snapshot-testing.html#should-snapshot-files-be-committed

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM