0

I have added the below steps to run unit test in Azure pipelines for React UI.

Added a file , File name:jestTrxProcessor.js. The content:

var builder = require("jest-trx-results-processor/dist/testResultsProcessor"); 
var builder = require("jest-trx-results-processor");
 
var processor = builder({
  outputFile: "jestTestresults.trx", 
});
 
module.exports = processor;
  1. In package.json I entered the below code:
"scripts": {
....
"test": "jest"
},
devdependencies{
 ...
 "jest": "^23.4.1",
  "jest-trx-results-processor": "0.0.7",
  "jsdom": "^11.12.0"
},
"jest": {
       "testResultsProcessor": "./__tests__/jestTrxProcessor.js",
    "reporters": [
"default",
[
  "jest-trx-results-processor",
  {
    "outputFile": "./__tests__/jestTestresults.trx",
  
  }
]]},

3.In the yaml file I added the below script:

- script: |
    npm install
    npm install jest-trx-results-processor --save-dev
    yarn add --dev jest-trx-results-processor
    npm run build
 
   # npm run test
  displayName: 'npm install and build'
  
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'VSTest'
    testResultsFiles: './__tests__/jestTestresults.trx'
    testRunTitle: 'FrontEnd Test'

I am getting the below error:

enter image description here

riQQ
  • 9,878
  • 7
  • 49
  • 66
Asterix
  • 331
  • 6
  • 22

1 Answers1

1

Failed to parse result files when VSTest is run Azure pipelines

According to the error message:

Publish Test Results Failed to parse result files: System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1

It means that you have attempted to parse something that is not an XML document or there is a issue with the generated trx file.

To troubleshooting this issue, please try to update the devdependencies jest jest-trx-results-processor:

  "devDependencies": {
    "jest": "^26.6.3",
    "jest-trx-results-processor": "~2.0.0"
  },

And try to select JUnit in TestResultsFormat:

enter image description here

Besides, the Jest testResultsProcessor property is deprecated, please try to use the jest-junit package for test reports:

Please check this thread for some more details.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135