Jest TypeScript测试在Jenkins中失败

时间:2019-08-28 13:18:03

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

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

这是Jenkins控制台的摘录:

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.

奇怪的是,杰斯特说“未找到测试”,但也说“ testMatch:... 38个匹配项”

1 个答案:

答案 0 :(得分:2)

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

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

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

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