Skip to content

Commit 384e253

Browse files
authored
Merge pull request #373 from tonyhallett/further-report-hiding
add options for hiding 0 coverable and 0% coverage rows in report
2 parents a77028b + a3cdf8c commit 384e253

File tree

7 files changed

+73
-4
lines changed

7 files changed

+73
-4
lines changed

FineCodeCoverageTests/AppOptionsProvider_Tests.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public void Should_Not_Default_Any_Other_AppOptions_Properties()
197197
nameof(IAppOptions.ShowCoveredInOverviewMargin),
198198
nameof(IAppOptions.ShowUncoveredInOverviewMargin),
199199
nameof(IAppOptions.ShowPartiallyCoveredInOverviewMargin),
200-
nameof(IAppOptions.ShowToolWindowToolbar)
200+
nameof(IAppOptions.ShowToolWindowToolbar),
201+
nameof(IAppOptions.Hide0Coverable)
201202
};
202203
CollectionAssert.AreEquivalent(expectedSetters.Select(s => $"set_{s}"), invocationNames);
203204
}
@@ -278,6 +279,8 @@ internal void Should_Use_Deseralized_String_From_Store_For_AppOption_Property(Fu
278279
{ nameof(IAppOptions.FunctionsExclude), new string[]{ "FunctionsExclude" } },
279280
{ nameof(IAppOptions.FunctionsInclude), new string[]{ "FunctionsInclude" } },
280281
{ nameof(IAppOptions.HideFullyCovered), true },
282+
{ nameof(IAppOptions.Hide0Coverable),true },
283+
{ nameof(IAppOptions.Hide0Coverage),true },
281284
{ nameof(IAppOptions.Include), new string[]{ "Include" } },
282285
{ nameof(IAppOptions.IncludeReferencedProjects),true},
283286
{ nameof(IAppOptions.IncludeTestAssembly),true},

FineCodeCoverageTests/MsCodeCoverage/RunSettingsTemplateReplacementsFactory_Tests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -692,5 +692,7 @@ internal class TestCoverageProjectOptions : IAppOptions
692692
public bool ShowUncoveredInOverviewMargin { get; set; }
693693
public bool ShowPartiallyCoveredInOverviewMargin { get; set; }
694694
public bool ShowToolWindowToolbar { get; set; }
695+
public bool Hide0Coverable { get; set; }
696+
public bool Hide0Coverage { get; set; }
695697
}
696698
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ ThresholdForCyclomaticComplexity When [cyclomatic complexity](https://en.wik
249249
StickyCoverageTable Set to true for coverage table to have a sticky thead.
250250
NamespacedClasses Set to false to show classes in report in short form. Affects grouping.
251251
HideFullyCovered Set to true to hide classes, namespaces and assemblies that are fully covered.
252+
Hide0Coverage Set to true to hide classes, namespaces and assemblies that have 0% coverage.
253+
Hide0Coverable Set to false to show classes, namespaces and assemblies that are not coverable.
252254
253255
Enabled Specifies whether or not coverage output is enabled
254256
RunWhenTestsFail By default coverage runs when tests fail. Set to false to prevent this. **Cannot be used in conjunction with RunInParallel**

SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs

+51-3
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,12 @@ private string HideGroupingCss()
831831
832832
private string ObserveAndHideFullyCovered()
833833
{
834-
if (!appOptionsProvider.Get().HideFullyCovered)
834+
var appOptions = appOptionsProvider.Get();
835+
if (!(appOptions.HideFullyCovered | appOptions.Hide0Coverage | appOptions.Hide0Coverable))
835836
{
836837
return "";
837838
}
838-
return @"
839+
var old = @"
839840
var targetNode = document;//document.querySelector('table.overview.table-fixed.stripped');
840841
841842
var config = { attributes: false, childList: true, subtree: true };
@@ -883,7 +884,54 @@ private string ObserveAndHideFullyCovered()
883884
var observer = new MutationObserver(callback);
884885
observer.observe(targetNode, config);
885886
";
886-
}
887+
var code = $@"
888+
function getCellValue(row, index){{
889+
return parseInt(row.cells[index].innerText);
890+
}}
891+
var targetNode = document;
892+
893+
var config = {{ attributes: false, childList: true, subtree: true }};
894+
895+
var callback = function(mutationsList, observer) {{
896+
var rows = document.querySelectorAll(""coverage-info table tbody tr"");
897+
for(var i=0;i<rows.length;i++){{
898+
var row = rows[i];
899+
let hide = false;
900+
901+
const coverable = getCellValue(row,3);
902+
const covered = getCellValue(row,1)
903+
if(coverable === 0){{
904+
if({appOptions.Hide0Coverable.ToString().ToLower()}){{
905+
hide = true;
906+
}}
907+
}} else if(covered === 0){{
908+
if({appOptions.Hide0Coverage.ToString().ToLower()}){{
909+
hide = true;
910+
}}
911+
}} else if(covered === coverable){{
912+
913+
const branchCovered = getCellValue(row,7);
914+
const branchTotal = getCellValue(row,8);
915+
916+
if(branchTotal === branchCovered){{
917+
if({appOptions.HideFullyCovered.ToString().ToLower()}){{
918+
hide = true;
919+
}}
920+
}}
921+
}}
922+
923+
if(hide){{
924+
row.style.display = ""none"";
925+
}}
926+
927+
}};
928+
}};
929+
930+
var observer = new MutationObserver(callback);
931+
observer.observe(targetNode, config);
932+
";
933+
return code;
934+
}
887935
888936
private string HackGroupingToAllowAll(int groupingLevel)
889937
{

SharedProject/Options/AppOptionsPage.cs

+8
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ You can also ignore additional attributes by adding to this list (short name or
253253
[Category(commonReportCategory)]
254254
[Description("Set to true to hide classes, namespaces and assemblies that are fully covered.")]
255255
public bool HideFullyCovered { get; set; }
256+
257+
[Category(commonReportCategory)]
258+
[Description("Set to false to show classes, namespaces and assemblies that are not coverable.")]
259+
public bool Hide0Coverable { get; set; }
260+
261+
[Category(commonReportCategory)]
262+
[Description("Set to true to hide classes, namespaces and assemblies that have 0% coverage.")]
263+
public bool Hide0Coverage { get; set; }
256264
#endregion
257265

258266
#region OpenCover report category

SharedProject/Options/AppOptionsProvider.cs

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private void AddDefaults(IAppOptions appOptions)
6868
appOptions.ShowCoveredInOverviewMargin = true;
6969
appOptions.ShowPartiallyCoveredInOverviewMargin = true;
7070
appOptions.ShowUncoveredInOverviewMargin = true;
71+
appOptions.Hide0Coverable = true;
7172
}
7273

7374
public void LoadSettingsFromStorage(IAppOptions instance)
@@ -179,6 +180,9 @@ internal class AppOptions : IAppOptions
179180

180181
public bool HideFullyCovered { get; set; }
181182

183+
public bool Hide0Coverable { get; set; }
184+
public bool Hide0Coverage { get; set; }
185+
182186
public bool AdjacentBuildOutput { get; set; }
183187

184188
public RunMsCodeCoverage RunMsCodeCoverage { get; set; }

SharedProject/Options/IAppOptions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ internal interface IAppOptions : IMsCodeCoverageOptions, IFCCCommonOptions
5454
bool StickyCoverageTable { get; set; }
5555
bool NamespacedClasses { get; set; }
5656
bool HideFullyCovered { get; set; }
57+
bool Hide0Coverable { get; set; }
58+
bool Hide0Coverage { get; set; }
5759
bool AdjacentBuildOutput { get; set; }
5860
RunMsCodeCoverage RunMsCodeCoverage { get; set; }
5961
bool ShowToolWindowToolbar { get; set; }

0 commit comments

Comments
 (0)