如何从开玩笑手表中排除文件? [英] How to Exclude files from jest watch?

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

问题描述

我正在使用 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 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:


  • __测试__


    • __ snapshots __ (由jest创建)

    • results (由我和要排除的目录创建)

    • __tests__
      • __snapshots__ (created by jest)
      • results (created by me and the directory to exclude)

      有人能说清楚吗?

      推荐答案

      来自你需要添加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>] #

      (默认值:[])在将这些路径视为
      '可见之前,所有模块路径匹配
      的正则表达式模式字符串数组'到模块加载器。如果给定模块的路径与模式的任何
      匹配,则在测试
      环境中不会需要()。这些模式字符串与完整路径匹配。使用
      < 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 config...

      modulePathIgnorePatterns: ["directoryNameToIgnore"]
      

      或:

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

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

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