我添加了以下步骤以在 Azure 管道中为 React UI 运行单元测试。
添加了一个文件,文件名:jestTrxProcessor.js。内容:
var builder = require("jest-trx-results-processor/dist/testResultsProcessor");
var builder = require("jest-trx-results-processor");
var processor = builder({
outputFile: "jestTestresults.trx",
});
module.exports = processor;
"scripts": {
....
"test": "jest"
},
devdependencies{
...
"jest": "^23.4.1",
"jest-trx-results-processor": "0.0.7",
"jsdom": "^11.12.0"
},
"jest": {
"testResultsProcessor": "./__tests__/jestTrxProcessor.js",
"reporters": [
"default",
[
"jest-trx-results-processor",
{
"outputFile": "./__tests__/jestTestresults.trx",
}
]]},
3.在 yaml 文件中,我添加了以下脚本:
- script: |
npm install
npm install jest-trx-results-processor --save-dev
yarn add --dev jest-trx-results-processor
npm run build
# npm run test
displayName: 'npm install and build'
- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: './__tests__/jestTestresults.trx'
testRunTitle: 'FrontEnd Test'
我收到以下错误:
答案 0 :(得分:1)
在运行 VSTest 时无法解析结果文件 Azure 管道
根据错误信息:
<块引用>发布测试结果无法解析结果文件: System.Xml.XmlException: 根级别的数据无效。 1号线, 位置 1
这意味着您尝试解析的内容不是 XML 文档,或者生成的 trx 文件存在问题。
要解决此问题,请尝试更新 devdependencies jest
jest-trx-results-processor
:
"devDependencies": {
"jest": "^26.6.3",
"jest-trx-results-processor": "~2.0.0"
},
并尝试在 JUnit
中选择 TestResultsFormat
:
另外,Jest testResultsProcessor property is deprecated,请尽量使用 jest-junit 包来做测试报告:
请查看this thread了解更多详情。