Search code examples
azure-devopsyamlvstest

Publish test result fails for VSTest in Azure Devops


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

  1. Added a file where package.json file resides: File name:jestTrxProcessor.js.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;
2. 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": "./jestTrxProcessor.js",
    "reporters": [
"default",
[
  "jest-trx-results-processor",
  {
    "outputFile": "./jestTrxProcessor.js",
  
  }
]]},

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

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

I am getting the below error once I run the pipeline in Azure Devops:

No tests found In /home/vsts/work/1/s 40 files checked. testMatch: /tests//.js?(x),**/?(.)+(spec|test).js?(x) - 0 matches testPathIgnorePatterns: /node_modules/ - 40 matches

I have searched for this folder and its no where created/exists. I am not getting what am I missing here. I am quite new to creation of yaml pipeline for react UI. Kindly help. Thank you in advance


Solution

  • No tests found In /home/vsts/work/1/s 40 files checked. testMatch: /tests//.js?(x),**/?(.)+(spec|test).js?(x) - 0 matches testPathIgnorePatterns: /node_modules/ - 40 matches

    Based on the error message, the jest test is finding the xx.js file under the __tests__ folder. This is due to the default testmatch rule.

    I could reproduce this issue.

    enter image description here

    To solve this issue, you need to change the following settings:

    1. Change the name of the folder where the xxx.js file is located to __tests__ .

    enter image description here

    2.Edit the testResultsProcessor path in package.json.

    Here is an example:

     "jest": {
         "testResultsProcessor": "./__tests__/jestTrxProcessor", 
      "reporters": [
        "default",
        [
          "jest-trx-results-processor",
          {
            "outputFile": "relative/path/to/resulting.trx"
           
          }
        ]
      ]
    
    
      }
    

    Result:

    enter image description here