问题
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.
回答1:
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.jsonEg
yarn add -D jest-junitornpm add --save-dev jest-junitAdd 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=htmlbecause I also wanted code coverage. To skip code coverage reporting, use these (npm or yarn) task arguments:
jest --ci --reporters=jest-junit --reporters=defaultNote that
--reporters=defaultis 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:
回答2:
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-processorCreate
jestTrxProcessor.jsfile with following content:var builder = require('jest-trx-results-processor'); var processor = builder({ outputFile: 'jestTestresults.trx' }); module.exports = processor;Updated
package.jsonfile 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
npmtask to VSTS build fornpm test. This will run jest tests and publish results tojestTestresults.trx- Add
Publish Test Resultstask of VSTS to addjestTestresults.trxresults in VSTS test.
You will be able to see JEST tests along with other tests.
回答3:
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-processorUpdated
package.jsonfile 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
npmtask to VSTS build fornpm testin the build pipeline. It should look like this:- Add
Publish Test Resultstask of VSTS to addjestTestresults.trxresults 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:
来源:https://stackoverflow.com/questions/51720050/how-to-publish-jest-unit-test-results-in-vsts-tests