首页 > 解决方案 > coveragePathIgnorePatterns - 忽略具有特定结尾的文件

问题描述

开玩笑:我试图忽略所有.stories.tsx以 example结尾的文件SomeFileName.stories.tsx。像这样在我的- package.json>*.stories.tsx里面添加:coveragePathIgnorePatternsjest

"jest": {
    "coveragePathIgnorePatterns": [
        ...
        "*.stories.tsx"
    ]
}

不幸的是,运行测试将为我的所有测试引发以下错误:

● 测试套件无法运行

SyntaxError: Invalid regular expression: /*.stories.tsx/: Nothing to repeat
    at String.match (<anonymous>)
    ...

我需要在里面添加什么才能完成coveragePathIgnorePatterns这项工作?

标签: jestjsglob

解决方案


我从 javascript 中引用我的,以将其排除在我的 package.json 和它自己的文件中,但无论哪种方式,您都可以指定模式而不转义文件名中的句点。双星号用于路径。

"jest": {
    "coveragePathIgnorePatterns": [
        ...
        "./**/*.stories.tsx",
        "./some_path/**/*.stories.tsx",
        "!./**/*.interface.tsx",
    ]
}

推荐阅读