I'm doing some slightly bizarre stuff using jest
for testing where I'm writing some stuff to disk. If I use the watch
flag in jest however then I'm finding (quite obviously) that each time I write something to disk the tests re-fire again.
I don't currently have any sort of configuration, and I've taken a look at the documentation but it's really not clear to me which option I need to be using to suppress watching particular files. I believe I can see options to exclude code from code-coverage, test execution but not the actual watcher.
In my case I've got a setup like this and I just want to suppress my results directory:
__tests__
__snapshots__
(created by jest)results
(created by me and the directory to exclude)
- testfile1.js
Can anyone shed some light on doing this?
to exclude a directory from jest testing use testPathIgnorePatterns
below in package.json i have configured to ignore the "src" directory
Based on Jest docs
should be the way you want to go. That works in
Jest > 23.x.x
watchPathIgnorePatterns
From the documentation you need to add modulePathIgnorePatterns which is an array of string values which will be matched against
https://facebook.github.io/jest/docs/configuration.html#modulepathignorepatterns-array-string
Add this to your config...
or :
I had the same problem when I had a directory that must not be tested, although I still wanted it to be inside of
__tests__
directory (e.g.__mocks__
).As @Chris Hawkes has pointed out in the comments you should not use a use relative paths in such case (no slashes). So inside of your
package.json
file add:That solved my problem.