I've found some questions on SO specific to version for jest unit test to publish its result in VSTS build Test Results tab. But no proper solution is found.
3 Answers
I've used a different approach, b/c after some research I found that the Jest testResultsProcessor property is deprecated. I'm using the jest-junit package for test reports (which has been worked on more recently than the jest-trx-results-processor, fwiw):
Add jest-junit to
package.json
Eg
yarn add -D jest-junit
ornpm add --save-dev jest-junit
Add a VSTS task to run Jest using the jest-junit results reporter
I used the Yarn task, but you can alternately use the npm task. I used these task arguments:
jest --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html
because I also wanted code coverage. To skip code coverage reporting, use these (npm or yarn) task arguments:
jest --ci --reporters=jest-junit --reporters=default
Note that
--reporters=default
is there b/c I wanted the default stdout in my build log.Add a Publish Test Results task
Since we're using the default path, the test results file will be written to
~/junit.xml
(Optional) Add a publish code coverage task, too
If you're running code coverage, you might as well add a task for publishing the code coverage results, too:
If you're using a YAML pipeline, here's equivalent YAML (note that we're using the yarn task instead of npm tasks, but that can be changed):
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-task.Yarn@2
displayName: 'Install dependencies'
inputs:
Arguments: install --no-progress
- task: geeklearningio.gl-vsts-tasks-yarn.yarn-task.Yarn@2
displayName: 'Unit tests'
inputs:
Arguments: 'test --ci --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura'
continueOnError: true # Test failures should be published before failing the build
- task: PublishTestResults@2
displayName: 'Publish Jest Unit Test Results'
inputs:
testResultsFiles: junit.xml
mergeTestResults: true
testRunTitle: 'Jest Unit Tests'
failTaskOnFailedTests: true
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage from Jest tests'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'
# reportDirectory: '$(System.DefaultWorkingDirectory)/coverage'
failIfCoverageEmpty: true

- 10,308
- 8
- 51
- 55
-
Thanks this helped a lot. Working well overall just two issues. One is the "Test File" filter shows each jest test as a seperate file, vs each dll/exe for the "vstest" assemblies, but it's not too bad as at least each test shows individually. The other issue is that a build seems limited to one "coverage" result and I build a webpack bundle which goes into a ASP.NET web app. The web app vstest coverage overwrites the jest coverage, but I still have the artifact with the full report so sort of have both. – Rory Nov 20 '18 at 15:40
-
1RE the first issue - have you checked the junit.xml file? Does it look right? You can tweak how the jest-junit reporter emits properties via config. Second issue sounds like a defect in Azure DevOps (not supporting more than 1 coverage report per build plan) - would be great to report it. I don't have that problem, b/c as of right now our UI code is built in a separate build plan from our server code. – crimbo Nov 20 '18 at 16:12
-
I had a look and it looked "ok" but wasn't really sure how that gets mapped to what azure DevOps expects. Will play around a bit and see if config can be tweaked to get better results. – Rory Nov 20 '18 at 20:10
-
@crimbo I've setup my Azure pipeline like this, but I just get a zip file of the coverage html/xml. Do you know how to get Azure to show coverage in the pipeline page? – Nick Jan 08 '20 at 16:02
-
@Nick - Try adding the publish code coverage task, step 4 in my answer. We're using Cobertura-formatted results from step 2. Take a look at your `cobertura-coverage.xml` file and see what is says. – crimbo Jan 15 '20 at 23:30
-
@crimbo Yeah I figured it out. It's still there as an artifact, but eventually our pipeline summary page loads an almost useless summary (single overall percentage of coverage). Azure DevOps 2019 IIRC. – Nick Jan 17 '20 at 21:28
-
2Very useful answer. You might also want to consider `continueOnError: true` (task level) for the `yarn test` task along with `failTaskOnFailedTests: true` (inputs level) on the `PublishTestResults` task so that test failures still cause the result to be uploaded, but the build still fails. – oatsoda Mar 24 '20 at 10:48
-
1@OffHeGoes - great suggestion. I'll update my answer so others don't have figure that out. – crimbo Mar 25 '20 at 20:11
-
@crimbo, the solution works perfectly for me. Thanks. Do you know if there is options to add screenshot attachment to the report, and when you publish the report it will give you a link so you can view the screenshot of fail test. – Phuong Duyen Huynh Ngoc May 12 '21 at 09:16
-
This is the best suggestion I found. The report produced with Cobertura is awesome, however I faced minor issue on how to configure jest to run this report, I tookhelp from this article: https://thenikhilk.com/2020/09/18/publish-code-coverage-azure-pipelines-react/ – aniruddha Jul 26 '21 at 09:51
I've gone throw some jest npm packages like tap-xunit
and jest-json-to-tap
but couldn't figure out it to work. Following steps worked for me to get the results to review under Test of VSTS build.
Install jest-trx-results-processor
# NPM npm install jest-trx-results-processor --save-dev # Yarn yarn add -D jest-trx-results-processor
Create
jestTrxProcessor.js
file with following content:var builder = require('jest-trx-results-processor'); var processor = builder({ outputFile: 'jestTestresults.trx' }); module.exports = processor;
Updated
package.json
file should look like:"devDependencies": { "jest": "^23.4.1", "jest-trx-results-processor": "0.0.7", "jsdom": "^11.12.0", ... }, "scripts": { "test": "jest" }, "jest": { ..., "testResultsProcessor": "./jestTrxProcessor.js" }
Add
npm
task to VSTS build fornpm test
. This will run jest tests and publish results tojestTestresults.trx
- Add
Publish Test Results
task of VSTS to addjestTestresults.trx
results in VSTS test.
You will be able to see JEST tests along with other tests.

- 13,739
- 11
- 55
- 107

- 2,135
- 2
- 30
- 51
Evaldas' solution is obsolete, so I'm going to add a few modifications.
The more modern solution is a combination between Evaldas' here, as well as the one from the maintainer: https://www.npmjs.com/package/jest-trx-results-processor
I'll describe it as such below.
Install jest-trx-results-processor
# NPM npm install jest-trx-results-processor --save-dev # Yarn yarn add -D jest-trx-results-processor
Updated
package.json
file should look like:"devDependencies": { "jest": "^24.9.0", "jest-trx-results-processor": "^1.0.2" ... }, "scripts": { "test": "jest" }, "jest": { ..., "reporters": [ "default", [ "jest-trx-results-processor", { "outputFile": "./src/jestTestresults.trx", "defaultUserName": "user name to use if automatic detection fails" } ]]}
Add
npm
task to VSTS build fornpm test
in the build pipeline. It should look like this:- Add
Publish Test Results
task of VSTS to addjestTestresults.trx
results in VSTS test. To do this, in the build pipeline, click on the 'add sign'. Look for "Publish Test Results". It'll bring up a menu like this. Since it's a .trx file, you'll need to use VSTest instead of JTest. - Finally, the build pipeline for your frontend project will look like this:

- 621
- 1
- 9
- 22
-
Would the "test results files" pattern need to match the actual file name? – topher-j Mar 27 '20 at 20:57
-
I think you can change that "test results files" file name, just be sure to reference the correct file in the Publish Test Results step. – Ryan Battistone Mar 31 '20 at 17:50