如何从Jest watch中排除文件? [英] How can I exclude files from Jest watch?

查看:91
本文介绍了如何从Jest watch中排除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jest做一些奇怪的事情,以测试我将一些东西写到磁盘上的情况.但是,如果我在Jest中使用watch标志,那么(很明显)我发现,每次我写一些东西到磁盘时,测试都会重新触发.

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 refire 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 and 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__(由Jest创建)
  • results(由我创建,要排除的目录)
  • __tests__
  • __snapshots__ (created by Jest)
  • results (created by me and the directory to exclude)
  • testfile1.js

我该怎么做?

推荐答案

从文档中,您需要添加modulePathIgnorePatterns,它是将与之匹配的字符串值的数组

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

modulePathIgnorePatterns [array< string>]#

modulePathIgnorePatterns [array<string>] #

(默认值:[])一个匹配的正则表达式模式字符串数组 针对所有模块路径,然后再考虑这些路径 对模块加载器可见".如果给定模块的路径与任何 的模式,在测试中将不是require() 环境.这些模式字符串与完整路径匹配.使用 < rootDir>字符串标记,以包含项目根目录的路径 目录,以防止它意外忽略您的所有文件 在可能具有不同根目录的不同环境中. 例如:['< rootDir>/build/'].

(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 <rootDir> 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: ['<rootDir>/build/'].

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

将此添加到您的配置...

Add this to your configuration...

modulePathIgnorePatterns: ["directoryNameToIgnore"]

或:

modulePathIgnorePatterns: ["<rootDir>/dist/"]

这篇关于如何从Jest watch中排除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆