我有Jest的测试报告。 我想在詹金斯展示结果。
我尝试使用jest-junit,但未能在Jenkins中发布junit xml
答案 0 :(得分:5)
根据评论,我实施的解决方案是:
将 jest-junit
添加到您的 package.json:
yarn add --dev jest-junit
在你的 jest 配置中,添加以下条目:
{
"testResultsProcessor": "jest-junit"
}
对我来说,在运行测试时会生成一个 junit.xml
文件。然后为了让 Jenkins 收集它们,您可以在后期阶段使用 junit
插件:
junit checksName: 'Jest Tests', testResults: 'junit.xml'
或者如果您使用“脚本化”而不是“声明性”语法,可以使用 try/finally:
try {
sh "jest --ci"
} finally {
junit checksName: 'Jest Tests', testResults: 'junit.xml'
}