How to publish Jest Unit Test Results in VSTS tests?

前端 未结 3 1643
半阙折子戏
半阙折子戏 2021-01-31 03:49

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条回答
  •  一个人的身影
    2021-01-31 04:08

    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.

    1. Install jest-trx-results-processor

      # NPM
      npm install jest-trx-results-processor --save-dev
      
      # Yarn
      yarn add -D jest-trx-results-processor
      
    2. Create jestTrxProcessor.js file with following content:

      var builder = require('jest-trx-results-processor');     
      var processor = builder({
          outputFile: 'jestTestresults.trx' 
      });
      module.exports = processor;
      
    3. 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"
      }
      
    4. Add npm task to VSTS build for npm test. This will run jest tests and publish results to jestTestresults.trx

    5. Add Publish Test Results task of VSTS to add jestTestresults.trx results in VSTS test.

    You will be able to see JEST tests along with other tests.

提交回复
热议问题