BlogFridays

In as much as we learn to be 'unique’, we must also yield to 'unite.' 'Unity' is the ever present recipe for the uniqueness we all possess to come to function. Our lights can be individually lit, but…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Publishing Merged Code Coverage Report of Nx Workspace in Azure CI Pipeline

Reviewing the code coverage result helps to identify code path(s) that are not covered by the tests. This information is important to improve the test collateral over time by reducing the test debt.

You can see at file level in azure pipeline

At this time Azure Pipeline only support showing code coverage using Cobertura or JaCoCo coverage formats only. I am using Cobertura in order to publish code coverage.

Since I have a Nrwl.Nx monorepo which has angular apps and libs. And when I run the test using --codeCoverage=true then it creates the cobertura-coverage.xml files. Read [Publish Code Coverage Nx Monorepo Angular in Azure Pipelines] to learn how to publish code coverage to azure pipeline.

Notice, I have coverage files from applications (apps) and libraries (libs)

We need to get the path of each cobertura-coverage.xml file.

Lets create a merge-codecoverage.js JavaScript file to search all xml files we will use glob npm package.

We will create merged-cobertura-coverage.xml which is combined of all of the report files.

In order to merge all of them we need below script.

Running the cobertura-merge script

Merged file created inside the merged folder

Merged cobertura-coverage.xml file

Here is the JavaScript for merging code coverage files.

Use below task to publish merged code coverage report in azure pipeline.

I changed the logging.service.ts in branding service. Which is used by both apps.

Run nx affected:dep-graph --base=main

Now lets run the azure pipeline and see if we can see the 3 projects code coverage is shown in merged fashion.

See 3 tests are running in azure pipeline

publishing code coverage in azure pipeline

Notice it published the code coverage report for all 3 projects.

I want to exclude the src folder root files from code coverage. We dont want to show test.ts or polyfills.ts coverage report.

Go to workspace.json file and identify your project names and in the test configuration insert code coverage exclude file list like below screenshot.

Now run nx run cutepuppies-client:test --codeCoverage=true

Now notice we do not have src folder files code coverage.

Lets do this exclude for all of our project’s test configuration.

Notice, I have code coverage from below projects.

I want to show the project names in the Code Coverage Report of Azure pipeline. Therefore, we will update the JavaScript code to put correct project name per code coverage file in our merged code coverage xml file. Like Below:

I need to generate & run below cobertura merge script to create correct merged code coverage file with project names.

Change the merge code coverage in JavaScript

🏃 Run your pipeline

💯 Showing Code Coverage percentages

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.

Add a comment

Related posts:

Enhancing cancer immunotherapy by restoring a warning system

Cancer cells often develop tactics to evade the immune system. A research team led by scientists at Memorial Sloan Kettering Cancer Center has identified one such mechanism, and it believes targeting…

Jasa Bonceng Spesial

Vinka beranjak dari ranjang, mengambil jaket yang tergantung di belakang pintu. Tak lupa dengan masker dan helm untuk menutupi wajahnya. Ia sengaja melakukan itu agar Rezhan tidak mengenalinya. Motor…

How To Be Less Busy

I recently gave a talk in front of a room full of founders on how to be a great leader. I shared four key concepts in the talk, but what the audience most resonated with was my advice to “be less…