vig*_*esh 3 junit mocha.js node.js azure-devops
我使用 PublishTestResults 任务创建了以下 YAML 文件,以在 Azure DevOps 门户中显示摩卡测试结果
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.14.1'
displayName: 'Install Node.js'
- script: |
npm install
mocha test --reporter mocha-junit-reporter
npm test
displayName: 'npm install and test'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testRunner: JUnit
testResultsFiles: '**/TEST-RESULTS.xml'
- task: ArchiveFiles@2
displayName: 'Archive $(System.DefaultWorkingDirectory)'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/node.zip'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
Run Code Online (Sandbox Code Playgroud)
但每当我运行构建时,我都会收到以下警告
"No test result files matching **/TEST-RESULTS.xml were found."
Run Code Online (Sandbox Code Playgroud)
主要动机是在仪表板或测试选项卡中单独显示摩卡测试结果。这样我们就不必在构建过程中检查测试任务来查看测试结果。
小智 7
我遇到了同样的问题,尝试了很多方法后可以解决它,如下所示。
步骤1.更新package.json
包含在scripts部分中:
"test": "cross-env CI=true react-scripts test --env=jsdom
--testPathIgnorePatterns=assets --reporters=default --reporters=jest-junit"
Run Code Online (Sandbox Code Playgroud)
在 jest 配置或 jest部分中包含以下内容package.json
"jest-junit": {
"suiteNameTemplate": "{filepath}",
"outputDirectory": ".",
"outputName": "junit.xml"
}
Run Code Online (Sandbox Code Playgroud)
本地运行npm run test看看是否junit.xml创建了。
步骤 2. 在 Azure Pipeline YAML 文件中
包含Npm带有自定义命令的任务,如下所示
- task: Npm@1
displayName: 'Run Tests'
inputs:
command: 'custom'
workingDir: "folder where your package.json exists"
customCommand: 'test'
Run Code Online (Sandbox Code Playgroud)
发布结果的任务
- task: PublishTestResults@2
displayName: 'Publish Unit Test Results'
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/junit.xml'
mergeTestResults: true
failTaskOnFailedTests: true
testRunTitle: 'React App Test'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9984 次 |
| 最近记录: |