gpt4 book ai didi

javascript - 使用 Jest 忽略 testMatch 中的特定文件夹模式

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:30:29 35 4
gpt4 key购买 nike

我试图忽略 Jest 的 testMatch 模式中的特定文件夹。

我在 __tests__ 文件夹中进行了测试,我希望能够将文件夹 __config__ 放入其中,其中应忽略所有文件。

/__tests__
/__config__
someConfig.jsx
/MyComponent.jsx
/MyComponent.jsx

我在 __tests__ 文件夹中的测试将从 __config__ 文件夹导入文件,所以我不想用 transformIgnorePatterns 忽略它们.

但如果我不忽略该文件夹,Jest 会尝试在该文件夹中运行并返回错误:

FAIL src/components/__tests__/__config__/someConfig.jsx

Your test suite must contain at least one test.

我尝试了几种不同的模式,但找不到忽略 __config__ 文件夹的方法

testMatch: [
"**/__tests__/!(__config__)/**/*.(js)?(x)", // Doesn't work
"**/__tests__/(**|!__config__)/*.(js)?(x)", // Doesn't work
"**/__tests__/(**|?!__config__)/*.(js)?(x)", // Doesn't work
"**/__tests__/{**,!__config__}/*.(js)?(x)", // Doesn't work
],

知道如何忽略这样的子文件夹吗?

最佳答案

请尝试使用 testPathIgnorePatterns

如果测试路径匹配任何模式,它将被跳过。

使用字符串标记来包含项目根目录的路径。

关于javascript - 使用 Jest 忽略 testMatch 中的特定文件夹模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47819927/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com