Is there a way to enable test coverage with thresholds using the nx test executor? #185
-
I've migrated an existing dotnet 5/angular app into a Nx mono repo, and most things seem to be working great. Previously, I had the following targets in my test project <Target Name="TestWithCoverage">
<Exec Command="dotnet test API.Tests.csproj @coverlet-coverage.rsp" WorkingDirectory="./" />
</Target>
<Target Name="TestWithReport">
<Exec Command="dotnet msbuild /t:TestWithCoverage" WorkingDirectory="./" ContinueOnError="WarnAndContinue" />
<Exec Command="dotnet reportgenerator -reports:./TestResults/lcov.info -targetdir:./TestResults/report" WorkingDirectory="./" />
</Target> with @coverlet-coverage.rsp as below
After moving into the Nx workspace, I've been trying to achieve similar using the nx test executor. The closest I've got is the following: angular.json with the api-test app configuration "api-test": {
"root": "apps/api-test",
"projectType": "application",
"sourceRoot": "apps/api-test",
"architect": {
"test": {
"builder": "@nx-dotnet/core:test",
"options": {
"settings": "coverlet.runsettings.xml"
}
}
}
} with coverlet.runsettings.xml as below <?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>..\..\coverage\api-test</ResultsDirectory>
<TreatNoTestsAsError>true</TreatNoTestsAsError>
</RunConfiguration>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>lcov</Format>
<SkipAutoProps>true</SkipAutoProps>
<!-- <CollectCoverage>true</CollectCoverage>
<Threshold>95.61 %2c 94.9 %2c 94.67</Threshold>
<ThresholdType>line %2c branch %2c method</ThresholdType> -->
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings> The problems that I am not sure how to solve are as follows:
A possible solution would be if there is a way to run the coverlet with the switches defined in the @coverlet-coverage.rsp, but I'm not sure how I would configure this in the angular.json test target. Not sure if I'm missing something obvious here. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There are a couple ways to solve this in the context of the nx monorepo. To get these to work as is, without changes on the I'll likely work on an msbuild executor in the near future, but would welcome a PR for one if anyone is watching 🚀 |
Beta Was this translation helpful? Give feedback.
There are a couple ways to solve this in the context of the nx monorepo. To get these to work as is, without changes on the
nx-dotnet
side, you can set some targets up in workspace.json / project.json files that use@nrwl/workspace:run-commands
as the executor. The docs for that are here: https://nx.dev/l/a/workspace/run-commands-executor. You may usedotnet msbuild \t:TestWithReport
as the command for example, with cwd set to the apps root.I'll likely work on an msbuild executor in the near future, but would welcome a PR for one if anyone is watching 🚀