开玩笑的 TypeScript 测试在 Jenkins 中失败
Jest TypeScript tests failing in Jenkins
我们有一个 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.
奇怪的是 Jest 说 "No tests found" 但也说 "testMatch: ... 38 matches"
提问者的队友,这最终变得更加微妙了。
这里的罪魁祸首是 testPathIgnorePatterns 中的 /lib/。 testPathIgnorePatterns 匹配由 testMatch 或 testRegex 找到的任何测试文件的完整路径。
事实证明,我们的 Jenkins 实例的工作目录类似于 /var/lib/jenkins/workspace
,因此 testMatch 会找到我们所有的测试文件,但随后 testPathIgnorePatterns 会在 /lib/ 上匹配它们并排除商场。
以与环境无关的方式排除“/lib/”文件夹的正确方法是像这样使用 <rootDir>
令牌
testPathIgnorePatterns: [
'<rootDir>/lib/',
],
我们有一个 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.
奇怪的是 Jest 说 "No tests found" 但也说 "testMatch: ... 38 matches"
提问者的队友,这最终变得更加微妙了。 这里的罪魁祸首是 testPathIgnorePatterns 中的 /lib/。 testPathIgnorePatterns 匹配由 testMatch 或 testRegex 找到的任何测试文件的完整路径。
事实证明,我们的 Jenkins 实例的工作目录类似于 /var/lib/jenkins/workspace
,因此 testMatch 会找到我们所有的测试文件,但随后 testPathIgnorePatterns 会在 /lib/ 上匹配它们并排除商场。
以与环境无关的方式排除“/lib/”文件夹的正确方法是像这样使用 <rootDir>
令牌
testPathIgnorePatterns: [
'<rootDir>/lib/',
],