How can I exclude files from Jest watch?

前端 未结 7 1676
眼角桃花
眼角桃花 2021-02-01 12:17

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 (quit

7条回答
  •  情深已故
    2021-02-01 13:07

    From the documentation you need to add modulePathIgnorePatterns which is an array of string values which will be matched against

    modulePathIgnorePatterns [array] #

    (default: []) An array of regexp pattern strings that are matched against all module paths before those paths are to be considered 'visible' to the module loader. If a given module's path matches any of the patterns, it will not be require()-able in the test environment. These pattern strings match against the full path. Use the string token to include the path to your project's root directory to prevent it from accidentally ignoring all of your files in different environments that may have different root directories. Example: ['/build/'].

    https://facebook.github.io/jest/docs/configuration.html#modulepathignorepatterns-array-string

    Add this to your configuration...

    modulePathIgnorePatterns: ["directoryNameToIgnore"]
    

    or:

    modulePathIgnorePatterns: ["/dist/"]
    

提交回复
热议问题