【问题标题】:Jest TypeScript tests failing in JenkinsJest TypeScript 测试在 Jenkins 中失败
【发布时间】:2020-01-01 17:45:58
【问题描述】:

我们有一个 React / TypeScript 项目,并使用 Jest + ts-jest 作为我们的测试运行器。在本地一切正常,但在我们的 Jenkins CI 中运行时失败。

这是来自 Jenkins 控制台的 sn-p:

No tests found, exiting with code 1
In /var/lib/jenkins/workspace/fix-jenkins-tests
  403 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[jt]s?(x) - 38 matches
  testPathIgnorePatterns: /lib/, /node_modules/ - 0 matches
  testRegex:  - 0 matches
Pattern:  - 0 matches
error Command failed with exit code 1.

奇怪的是,Jest 说“未找到测试”但还说“testMatch: ... 38 匹配”

【问题讨论】:

    标签: typescript jenkins jestjs jenkins-pipeline ts-jest


    【解决方案1】:

    这里是提问者的队友,这最终变得更加微妙。 这里的罪魁祸首是 testPathIgnorePatterns 中的 /lib/。 testPathIgnorePatterns 与 testMatch 或 testRegex 找到的任何测试文件的完整路径匹配。

    事实证明,我们的 Jenkins 实例的工作目录类似于 /var/lib/jenkins/workspace,因此 testMatch 会找到我们所有的测试文件,但随后 testPathIgnorePatterns 会将它们全部匹配到 /lib/ 并排除它们。

    以与环境无关的方式排除“/lib/”文件夹的正确方法是像这样使用<rootDir> 标记

    testPathIgnorePatterns: [ '<rootDir>/lib/', ],

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-04
      • 2020-12-28
      • 1970-01-01
      相关资源
      最近更新 更多