@@ -13,6 +13,7 @@ import {
13
13
compareCategoryAuditsAndGroups ,
14
14
compareIssueSeverity ,
15
15
compareIssues ,
16
+ countCategoryAudits ,
16
17
countWeightedRefs ,
17
18
formatDiffNumber ,
18
19
formatReportScore ,
@@ -53,6 +54,12 @@ describe('formatScoreWithColor', () => {
53
54
it ( 'should skip round value and optionally skip bold formatting' , ( ) => {
54
55
expect ( formatScoreWithColor ( 0.123 ) . toString ( ) ) . toBe ( '🔴 **12**' ) ;
55
56
} ) ;
57
+
58
+ it ( 'should skip bold formatting' , ( ) => {
59
+ expect ( formatScoreWithColor ( 0.123 , { skipBold : true } ) . toString ( ) ) . toBe (
60
+ '🔴 12' ,
61
+ ) ;
62
+ } ) ;
56
63
} ) ;
57
64
58
65
describe ( 'colorByScoreDiff' , ( ) => {
@@ -119,6 +126,54 @@ describe('countWeightedRefs', () => {
119
126
] ) ,
120
127
) . toBe ( 1 ) ;
121
128
} ) ;
129
+
130
+ it ( 'should include multiple weighted references' , ( ) => {
131
+ expect (
132
+ countWeightedRefs ( [
133
+ {
134
+ slug : 'a1' ,
135
+ weight : 0.5 ,
136
+ plugin : 'a' ,
137
+ type : 'audit' ,
138
+ } ,
139
+ {
140
+ slug : 'a2' ,
141
+ weight : 0.3 ,
142
+ plugin : 'a' ,
143
+ type : 'audit' ,
144
+ } ,
145
+ {
146
+ slug : 'a3' ,
147
+ weight : 0.2 ,
148
+ plugin : 'a' ,
149
+ type : 'audit' ,
150
+ } ,
151
+ ] ) ,
152
+ ) . toBe ( 1 ) ;
153
+ } ) ;
154
+
155
+ it ( 'should return 0 when all weights are 0' , ( ) => {
156
+ expect (
157
+ countWeightedRefs ( [
158
+ {
159
+ slug : 'a1' ,
160
+ weight : 0 ,
161
+ plugin : 'a' ,
162
+ type : 'audit' ,
163
+ } ,
164
+ {
165
+ slug : 'a2' ,
166
+ weight : 0 ,
167
+ plugin : 'a' ,
168
+ type : 'audit' ,
169
+ } ,
170
+ ] ) ,
171
+ ) . toBe ( 0 ) ;
172
+ } ) ;
173
+
174
+ it ( 'should handle cases when no weights are provided' , ( ) => {
175
+ expect ( countWeightedRefs ( [ ] ) ) . toBe ( 0 ) ;
176
+ } ) ;
122
177
} ) ;
123
178
124
179
describe ( 'compareIssueSeverity' , ( ) => {
@@ -234,14 +289,30 @@ describe('sortAudits', () => {
234
289
} ) ;
235
290
236
291
describe ( 'getPluginNameFromSlug' , ( ) => {
237
- it ( 'should return plugin name ' , ( ) => {
292
+ it ( 'should return plugin title ' , ( ) => {
238
293
const plugins = [
239
294
{ slug : 'plugin-a' , title : 'Plugin A' } ,
240
295
{ slug : 'plugin-b' , title : 'Plugin B' } ,
241
296
] as ScoredReport [ 'plugins' ] ;
242
297
expect ( getPluginNameFromSlug ( 'plugin-a' , plugins ) ) . toBe ( 'Plugin A' ) ;
243
298
expect ( getPluginNameFromSlug ( 'plugin-b' , plugins ) ) . toBe ( 'Plugin B' ) ;
244
299
} ) ;
300
+
301
+ it ( 'should return plugin slug when plugin title is an empty string' , ( ) => {
302
+ expect (
303
+ getPluginNameFromSlug ( 'plugin-a' , [
304
+ { slug : 'plugin-a' , title : '' } ,
305
+ ] as ScoredReport [ 'plugins' ] ) ,
306
+ ) . toBe ( 'plugin-a' ) ;
307
+ } ) ;
308
+
309
+ it ( 'should return provided slug when plugin slug and title are empty strings' , ( ) => {
310
+ expect (
311
+ getPluginNameFromSlug ( 'plugin-a' , [
312
+ { slug : '' , title : '' } ,
313
+ ] as ScoredReport [ 'plugins' ] ) ,
314
+ ) . toBe ( 'plugin-a' ) ;
315
+ } ) ;
245
316
} ) ;
246
317
247
318
describe ( 'sortAuditIssues' , ( ) => {
@@ -476,6 +547,7 @@ describe('formatValueChange', () => {
476
547
[ { before : 600 , after : 450 , diff : - 150 } , '↓ −25 %' ] ,
477
548
[ { before : 1 , after : 3 , diff : 2 } , '↑ +200 %' ] ,
478
549
[ { before : 0 , after : 2 , diff : 2 } , '↑ +∞ %' ] ,
550
+ [ { before : 0 , after : - 2 , diff : - 2 } , '↓ −∞ %' ] ,
479
551
[ { before : 100 , after : 101 , diff : 1 } , '↑ +1 %' ] ,
480
552
[ { before : 1000 , after : 1001 , diff : 1 } , '↑ +0.1 %' ] ,
481
553
[ { before : 500 , after : 499 , diff : - 1 } , '↓ −0.2 %' ] ,
@@ -492,3 +564,138 @@ describe('formatValueChange', () => {
492
564
} ,
493
565
) ;
494
566
} ) ;
567
+
568
+ describe ( 'countCategoryAudits' , ( ) => {
569
+ it ( 'should count single audit references' , ( ) => {
570
+ expect (
571
+ countCategoryAudits (
572
+ [
573
+ {
574
+ type : 'audit' ,
575
+ plugin : 'coverage' ,
576
+ slug : 'function-coverage' ,
577
+ weight : 1 ,
578
+ } ,
579
+ ] ,
580
+ [ ] ,
581
+ ) ,
582
+ ) . toBe ( 1 ) ;
583
+ } ) ;
584
+
585
+ it ( 'should count audits in a group' , ( ) => {
586
+ expect (
587
+ countCategoryAudits (
588
+ [
589
+ {
590
+ type : 'group' ,
591
+ plugin : 'coverage' ,
592
+ slug : 'code-coverage' ,
593
+ weight : 1 ,
594
+ } ,
595
+ ] ,
596
+ [
597
+ {
598
+ slug : 'coverage' ,
599
+ groups : [
600
+ {
601
+ slug : 'code-coverage' ,
602
+ refs : [
603
+ { slug : 'branch-coverage' , weight : 0.33 } ,
604
+ { slug : 'function-coverage' , weight : 0.33 } ,
605
+ { slug : 'line-coverage' , weight : 0.33 } ,
606
+ ] ,
607
+ } ,
608
+ ] ,
609
+ } ,
610
+ ] as ScoredReport [ 'plugins' ] ,
611
+ ) ,
612
+ ) . toBe ( 3 ) ;
613
+ } ) ;
614
+
615
+ it ( 'should handle mixed audit and group references' , ( ) => {
616
+ expect (
617
+ countCategoryAudits (
618
+ [
619
+ {
620
+ type : 'audit' ,
621
+ plugin : 'lighthouse' ,
622
+ slug : 'is-on-https' ,
623
+ weight : 1 ,
624
+ } ,
625
+ {
626
+ type : 'group' ,
627
+ plugin : 'coverage' ,
628
+ slug : 'code-coverage' ,
629
+ weight : 1 ,
630
+ } ,
631
+ ] ,
632
+ [
633
+ {
634
+ slug : 'coverage' ,
635
+ groups : [
636
+ {
637
+ slug : 'code-coverage' ,
638
+ refs : [
639
+ { slug : 'branch-coverage' , weight : 0.5 } ,
640
+ { slug : 'line-coverage' , weight : 0.5 } ,
641
+ ] ,
642
+ } ,
643
+ ] ,
644
+ } ,
645
+ ] as ScoredReport [ 'plugins' ] ,
646
+ ) ,
647
+ ) . toBe ( 3 ) ;
648
+ } ) ;
649
+
650
+ it ( 'should return 0 when a group is not found' , ( ) => {
651
+ expect (
652
+ countCategoryAudits (
653
+ [
654
+ {
655
+ type : 'group' ,
656
+ plugin : 'plugin-A' ,
657
+ slug : 'missing-group' ,
658
+ weight : 1 ,
659
+ } ,
660
+ ] ,
661
+ [
662
+ {
663
+ slug : 'plugin-A' ,
664
+ groups : [
665
+ {
666
+ slug : 'code-coverage' ,
667
+ refs : [
668
+ { slug : 'branch-coverage' , weight : 0.5 } ,
669
+ { slug : 'line-coverage' , weight : 0.5 } ,
670
+ ] ,
671
+ } ,
672
+ ] ,
673
+ } ,
674
+ ] as ScoredReport [ 'plugins' ] ,
675
+ ) ,
676
+ ) . toBe ( 0 ) ;
677
+ } ) ;
678
+
679
+ it . each ( [ [ [ ] ] , [ undefined ] ] ) (
680
+ 'should return 0 when plugin groups are %p and no single audit references are provided' ,
681
+ groups => {
682
+ expect (
683
+ countCategoryAudits (
684
+ [
685
+ {
686
+ type : 'group' ,
687
+ plugin : 'coverage' ,
688
+ slug : 'code-coverage' ,
689
+ weight : 1 ,
690
+ } ,
691
+ ] ,
692
+ [ { slug : 'coverage' , groups : groups } ] as ScoredReport [ 'plugins' ] ,
693
+ ) ,
694
+ ) . toBe ( 0 ) ;
695
+ } ,
696
+ ) ;
697
+
698
+ it ( 'should return 0 when no audits or groups are present' , ( ) => {
699
+ expect ( countCategoryAudits ( [ ] , [ ] ) ) . toBe ( 0 ) ;
700
+ } ) ;
701
+ } ) ;
0 commit comments