如何在 Jest 中忽略 git worktree 中的测试目录?

问题描述 投票:0回答:1

我正在将 Jest 与 git 工作树一起使用。我的工作树的一个分支位于一个单独的目录中。因此,我有两个

__tests__
目录,
./__tests__
docusaurus/__tests__/
。我想忽略 docusaurus 中的
tests
目录。我怎么做? 指定笑话测试文件目录没有帮助。

我尝试过 JavaScript 代码:

    testMatch: [
        '__tests__/*.spec.js'
    ]

和:

    testMatch: [
        './__tests__/*.spec.js'
    ]

但是代码不起作用,Jest 找不到我的 __test__ 目录中的

any
。我不想将 docusaurus 添加到我的忽略文件中。这意味着我每次创建工作树时都必须更改配置文件。

这是我的配置:

module.exports = {
    testEnvironment: 'jsdom',
    verbose: true,
    modulePathIgnorePatterns: [
        "\\/\\.#"
    ],
    testPathIgnorePatterns: [
        "\\/\\.#"
    ],
    testMatch: [
        "**/__tests__/*.spec.js"
    ]
};

创建最小复制:

  1. 创建一个空的 git 存储库
  2. 添加
    __test__/something.spec.js
    单次测试文件
  3. 提交到 git 存储库
  4. 创建分支
  5. 从分支创建工作树
  6. 运行笑话

Jest 支持吗?

这里是复制:https://github.com/jcubic/jest-so

javascript git jestjs git-worktree
1个回答
0
投票

看来这可行:

testPathIgnorePatterns: [
    "<rootDir>/.*/__tests__"
]

因为ignore是一个正则表达式模式,所以你不能像testMatch那样使用

**
,它是一个glob。

© www.soinside.com 2019 - 2024. All rights reserved.