0
votes

I have created the below YAML file with the PublishTestResults task to display the mocha test results in Azure DevOps portal

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.14.1'
  displayName: 'Install Node.js'

- script: |
    npm install
    mocha test --reporter mocha-junit-reporter
    npm test
  displayName: 'npm install and test'

- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testRunner: JUnit
    testResultsFiles: '**/TEST-RESULTS.xml'

- task: ArchiveFiles@2
  displayName: 'Archive $(System.DefaultWorkingDirectory)'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/node.zip'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

but whenever I run the build I am getting the following warning

"No test result files matching **/TEST-RESULTS.xml were found."

The main motive is to display the mocha test results separately in a dashboard or a test tab. So that we don't have to check the test task in build process to see the test results.

1
And when you run those tests locally, do you think it does create test result files named TEST-RESULTS.xml?jonrsharpe
yes it creates a file test-results.xml in my localvignesh ramesh
Hi @vigneshramesh, The PublishTestResults task default search path is $(System.DefaultWorkingDirectory), in the next task, we could see that you archive the Root folder $(System.DefaultWorkingDirectory), could you please check the node.zip file and ensure that it contain the file TEST-RESULTS.xml? Please check it and then kindly share the result here.Vito Liu
Hi @vigneshramesh, Just checking in to see whether this issue is still blocking you now? Any update for this issue?Vito Liu

1 Answers

2
votes

I encountered same issue, After trying bunch of things could solve it as below.

Step 1. Update package.json

  1. Include in scripts section:

    "test": "cross-env CI=true react-scripts test --env=jsdom
    --testPathIgnorePatterns=assets --reporters=default --reporters=jest-junit"
    
  2. Include below in jest config or jest section in package.json

    "jest-junit": {
        "suiteNameTemplate": "{filepath}",
        "outputDirectory": ".",
        "outputName": "junit.xml"
    }
    

    Run npm run test locally and see if junit.xml is created.

Step 2. In Azure Pipeline YAML file

  1. Include an Npm task with custom command as below

    - task: Npm@1
      displayName: 'Run Tests'
      inputs:
        command: 'custom'
        workingDir: "folder where your package.json exists"
        customCommand: 'test'
    
  2. Task to publish Results

    - task: PublishTestResults@2
      displayName: 'Publish Unit Test Results'
      condition: succeededOrFailed()
      inputs:
          testResultsFormat: 'JUnit'
          testResultsFiles: '**/junit.xml'
          mergeTestResults: true
          failTaskOnFailedTests: true
          testRunTitle: 'React App Test'
    

Publish Test Results