DEV Community

Cover image for Publishing Nx Monorepo Test Results in Azure CI Pipeline
Rupesh Tiwari
Rupesh Tiwari

Posted on

Publishing Nx Monorepo Test Results in Azure CI Pipeline

Publish Test Results task publishes test results to Azure CI Pipelines.

Step 1: Publish Unit Test Summary Report

Step 1 - To generate Test Report I’m using Karma JUnit Reporter. First install it to your project.
npm i karma-junit-reporter -D

Step 2 — Now we have to import above ‘karma-junit-reporter’ in to our project and have to configure. So for that, open ‘karma.conf.js’ file in your project. There, in the ‘plugins’ section, add the following line.

Step 3 — Now we have to say use this ‘karma-junit-reporter’ to generate Test Report. For that, in ‘karma.conf.js’ file, you can see a section ‘reporter’. Add the following inside the array.

Step 4 — okay. Now we have said to use JUnit repoter service to generate our Test Report. But to where ? We have to say, where to publish the Test Report. For that, add the following Code Snippet, before the ‘reporters’ section.


junitReporter: {
    outputDir: 'testresults/junit',
    outputFile: 'unit-test-result.xml',
    useBrowserName: false,
},
Enter fullscreen mode Exit fullscreen mode

Step 5- In the Azure DevOps Build Pipeline. ‘Publish Test Results’. Click on + symbol and search ‘Publish Test Results’. Add it.

Add below task in your azure-pipelines.yml file. You can skip the condition. I needed that for my Nx Monorepo project. You can just have task and inputs only.

Azure devops task supports merging multiple test results files out of the box. For that we will use mergeTestResults: true flag.

    # Publish Test Results
    # Publish Test Results
  - task: PublishTestResults@2
    inputs:
      testResultsFormat: 'JUnit'
      testResultsFiles: '**/testresults/**/*.xml'
      mergeTestResults: true
    condition: |
      and(
        succeeded(),
        not(contains(
            variables['COMMANDS'],
            '"test":[]'
        ))
      )

Enter fullscreen mode Exit fullscreen mode

Test results files created

When you run test now you should see test results file.

In order to avoid check-in them in git repo consider updating .gitignore

# Test Results
testresults/
Enter fullscreen mode Exit fullscreen mode

Running Build in Azure Pipeline


Become full stack developer 💻

If you want to become full stack developer and grow your carrier as new software developer or Lead Developer/Architect. Consider subscribing to our full stack development training programs. We have All-Access Monthly membership plans and you will get unlimited access to all of our video courses, slides, source code & Monthly video calls.

  • Please subscribe to All-Access Membership PRO plan to access current and future angular, node.js and related courses.
  • Please subscribe to All-Access Membership ELITE plan to get everything from PRO plan. Additionally, you will get access to monthly live Q&A video call with Rupesh and you can ask doubts/questions and get more help, tips and tricks.

You bright future is waiting for you so visit today FullstackMaster and allow me to help you to board on your dream software company as a Developer,Architect or Lead Engineer role.


Top comments (0)