Skip to content

Commit 58f8acd

Browse files
authored
mutationobserver to hide if fully covered. (#207)
1 parent b81fc8b commit 58f8acd

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ ThresholdForCrapScore When [crap score](https://testing.googleblog.
130130
131131
StickyCoverageTable Set to true for coverage table to have a sticky thead.
132132
NamespacedClasses Set to false to show classes in report in short form. Affects grouping.
133+
HideFullyCovered Set to true to hide classes, namespaces and assemblies that are fully covered.
133134
134135
RunSettingsOnly Specify false for global and project options to be used for coverlet data collector configuration elements when not specified in runsettings
135136
CoverletCollectorDirectoryPath Specify path to directory containing coverlet collector files if you need functionality that the FCC version does not provide.

SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs

+57
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,62 @@ private string HideGroupingCss()
765765
";
766766
}
767767
768+
private string ObserveAndHideFullyCovered()
769+
{
770+
if (!appOptionsProvider.Get().HideFullyCovered)
771+
{
772+
return "";
773+
}
774+
return @"
775+
var targetNode = document;//document.querySelector('table.overview.table-fixed.stripped');
776+
777+
var config = { attributes: false, childList: true, subtree: true };
778+
779+
var callback = function(mutationsList, observer) {
780+
var fullyCoveredTds = document.querySelectorAll('td.covered100.green')
781+
782+
for (var i = 0; i < fullyCoveredTds.length; i++)
783+
{
784+
var td = fullyCoveredTds[i];
785+
var parent = td.parentNode;
786+
if (parent.nodeName === 'TABLE')
787+
{
788+
parent = parent.parentNode;
789+
if (parent.nodeName === 'COVERAGE-BAR')
790+
{
791+
parent = parent.parentNode;
792+
if (parent.nodeName === 'TD' || parent.nodeName === 'TH')
793+
{
794+
parent = parent.parentNode;
795+
var coverageBars = parent.querySelectorAll('td>coverage-bar');
796+
if(coverageBars.length == 0){
797+
coverageBars = parent.querySelectorAll('th>coverage-bar');
798+
}
799+
var shouldHide = true;
800+
// currently there is no option to hide branch coverage.
801+
if(coverageBars.length === 2){
802+
var branchCoverageBar = coverageBars[1];
803+
// includes gray
804+
var td = branchCoverageBar.querySelector('table>td.covered100');
805+
if(!td){
806+
shouldHide = false;
807+
}
808+
}
809+
if(shouldHide){
810+
parent.style.setProperty('display', 'none');
811+
}
812+
}
813+
}
814+
815+
}
816+
}
817+
};
818+
819+
var observer = new MutationObserver(callback);
820+
observer.observe(targetNode, config);
821+
";
822+
}
823+
768824
private string HackGroupingToAllowAll(int groupingLevel)
769825
{
770826
return $@"
@@ -933,6 +989,7 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
933989
<script type=""text/javascript"">
934990
{GetStickyTableHead()}
935991
{HackGroupingToAllowAll(groupingLevel)}
992+
{ObserveAndHideFullyCovered()}
936993
function getRuleBySelector(cssRules,selector){{
937994
for(var i=0;i<cssRules.length;i++){{
938995
if(cssRules[i].selectorText == selector){{

SharedProject/Options/AppOptions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ You can also ignore additional attributes by adding to this list (short name or
163163
[Description("Set to false to show classes in report in short form.")]
164164
public bool NamespacedClasses { get; set; } = true;
165165

166+
[Category(reportCategory)]
167+
[Description("Set to true to hide classes, namespaces and assemblies that are fully covered.")]
168+
public bool HideFullyCovered { get; set; }
169+
166170
[SuppressMessage("Usage", "VSTHRD010:Invoke single-threaded types on Main thread")]
167171
public override void SaveSettingsToStorage()
168172
{

SharedProject/Options/IAppOptions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ public interface IAppOptions
2424
bool CoverageColoursFromFontsAndColours { get; }
2525
bool StickyCoverageTable { get; }
2626
bool NamespacedClasses { get; }
27+
bool HideFullyCovered { get; }
2728
}
2829
}

0 commit comments

Comments
 (0)