Skip to content

Instantly share code, notes, and snippets.

@atlefren
Created August 3, 2021 07:39
Show Gist options
  • Save atlefren/887d851c756ef1d6ef227fe09f51d37e to your computer and use it in GitHub Desktop.
Save atlefren/887d851c756ef1d6ef227fe09f51d37e to your computer and use it in GitHub Desktop.
Setting up test reporting and code coverage on Azure Devops pipelines in a js/ts project with jest
coverage
test/junit.xml
{
"scripts": {
"test:ci": "jest --env=jsdom --ci --coverage",
},
"devDependencies": {
"@types/jest": "^25.2.3",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"jest-junit": "^10.0.0",
"ts-jest": "^26.5.6",
},
"jest": {
"coverageReporters": [
"cobertura",
"html"
],
"collectCoverageFrom": [
"src/**/*.js",
"src/**/*.ts",
"src/**/*.tsx",
"!/node_modules/"
],
"transform": {
"\\.(ts|tsx)$": "ts-jest"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/build/"
],
"reporters": [
"default",
[
"jest-junit",
{
"outputDirectory": "test",
"outputName": "junit.xml"
}
]
]
},
"jest-junit": {
"suiteName": "jest tests",
"output": "test/junit.xml",
"classNameTemplate": "{classname} - {title}",
"titleTemplate": "{classname} - {title}",
"ancestorSeparator": " > ",
"usePathForSuiteName": "true"
}
}
#Run the test:ci task
- task: Npm@1
displayName: 'npm test'
inputs:
command: custom
verbose: false
customCommand: 'run test:ci'
#publish the tests results
- task: PublishTestResults@2
displayName: 'Publish Test Results '
inputs:
testResultsFiles: test/junit.xml
condition: succeededOrFailed()
#publish code coverage reports in cobertura format
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
condition: succeededOrFailed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment