1
1
import { describe , expect } from 'vitest' ;
2
2
import type { CategoryConfig , PluginConfig } from '@code-pushup/models' ;
3
- import { getLogMessages } from '@code-pushup/test-utils' ;
4
3
import { ui } from '@code-pushup/utils' ;
5
4
import type { FilterOptionType , Filterables } from './filter.model.js' ;
6
5
import {
@@ -19,22 +18,22 @@ describe('validateFilterOption', () => {
19
18
[
20
19
'onlyPlugins' ,
21
20
[ 'p1' , 'p3' , 'p4' ] ,
22
- 'The --onlyPlugins argument references plugins that do not exist: p3, p4.' ,
21
+ 'The --onlyPlugins argument references plugins that do not exist: p3, p4. The only valid plugin is p1. ' ,
23
22
] ,
24
23
[
25
24
'onlyPlugins' ,
26
25
[ 'p1' , 'p3' ] ,
27
- 'The --onlyPlugins argument references a plugin that does not exist: p3.' ,
26
+ 'The --onlyPlugins argument references a plugin that does not exist: p3. The only valid plugin is p1. ' ,
28
27
] ,
29
28
[
30
29
'onlyCategories' ,
31
30
[ 'c1' , 'c3' , 'c4' ] ,
32
- 'The --onlyCategories argument references categories that do not exist: c3, c4.' ,
31
+ 'The --onlyCategories argument references categories that do not exist: c3, c4. The only valid category is c1. ' ,
33
32
] ,
34
33
[
35
34
'onlyCategories' ,
36
35
[ 'c1' , 'c3' ] ,
37
- 'The --onlyCategories argument references a category that does not exist: c3.' ,
36
+ 'The --onlyCategories argument references a category that does not exist: c3. The only valid category is c1. ' ,
38
37
] ,
39
38
] ) (
40
39
'should log a warning if the only argument %s references nonexistent slugs %o along with valid ones' ,
@@ -51,31 +50,30 @@ describe('validateFilterOption', () => {
51
50
} ,
52
51
{ itemsToFilter, skippedItems : [ ] , verbose : false } ,
53
52
) ;
54
- const logs = getLogMessages ( ui ( ) . logger ) ;
55
- expect ( logs [ 0 ] ) . toContain ( expected ) ;
53
+ expect ( ui ( ) ) . toHaveLogged ( 'warn' , expected ) ;
56
54
} ,
57
55
) ;
58
56
59
57
it . each ( [
60
58
[
61
59
'skipPlugins' ,
62
60
[ 'p3' , 'p4' ] ,
63
- 'The --skipPlugins argument references plugins that do not exist: p3, p4.' ,
61
+ 'The --skipPlugins argument references plugins that do not exist: p3, p4. The only valid plugin is p1. ' ,
64
62
] ,
65
63
[
66
64
'skipPlugins' ,
67
65
[ 'p3' ] ,
68
- 'The --skipPlugins argument references a plugin that does not exist: p3.' ,
66
+ 'The --skipPlugins argument references a plugin that does not exist: p3. The only valid plugin is p1. ' ,
69
67
] ,
70
68
[
71
69
'skipCategories' ,
72
70
[ 'c3' , 'c4' ] ,
73
- 'The --skipCategories argument references categories that do not exist: c3, c4.' ,
71
+ 'The --skipCategories argument references categories that do not exist: c3, c4. The only valid category is c1. ' ,
74
72
] ,
75
73
[
76
74
'skipCategories' ,
77
75
[ 'c3' ] ,
78
- 'The --skipCategories argument references a category that does not exist: c3.' ,
76
+ 'The --skipCategories argument references a category that does not exist: c3. The only valid category is c1. ' ,
79
77
] ,
80
78
] ) (
81
79
'should log a warning if the skip argument %s references nonexistent slugs %o' ,
@@ -95,8 +93,7 @@ describe('validateFilterOption', () => {
95
93
} ,
96
94
{ itemsToFilter, skippedItems : [ ] , verbose : false } ,
97
95
) ;
98
- const logs = getLogMessages ( ui ( ) . logger ) ;
99
- expect ( logs [ 0 ] ) . toContain ( expected ) ;
96
+ expect ( ui ( ) ) . toHaveLogged ( 'warn' , expected ) ;
100
97
} ,
101
98
) ;
102
99
@@ -111,7 +108,7 @@ describe('validateFilterOption', () => {
111
108
} ,
112
109
{ itemsToFilter : [ 'p1' ] , skippedItems : [ ] , verbose : false } ,
113
110
) ;
114
- expect ( getLogMessages ( ui ( ) . logger ) ) . toHaveLength ( 0 ) ;
111
+ expect ( ui ( ) ) . not . toHaveLogs ( ) ;
115
112
} ) ;
116
113
117
114
it ( 'should log a category ignored as a result of plugin filtering' , ( ) => {
@@ -130,9 +127,10 @@ describe('validateFilterOption', () => {
130
127
} ,
131
128
{ itemsToFilter : [ 'p1' ] , skippedItems : [ ] , verbose : true } ,
132
129
) ;
133
- expect ( getLogMessages ( ui ( ) . logger ) ) . toHaveLength ( 1 ) ;
134
- expect ( getLogMessages ( ui ( ) . logger ) [ 0 ] ) . toContain (
135
- 'The --onlyPlugins argument removed the following categories: c1, c3' ,
130
+ expect ( ui ( ) ) . toHaveLoggedTimes ( 1 ) ;
131
+ expect ( ui ( ) ) . toHaveLogged (
132
+ 'info' ,
133
+ 'The --onlyPlugins argument removed the following categories: c1, c3.' ,
136
134
) ;
137
135
} ) ;
138
136
@@ -221,10 +219,16 @@ describe('validateFilterOption', () => {
221
219
{ plugins, categories } ,
222
220
{ itemsToFilter : [ 'p1' ] , skippedItems : [ 'p1' ] , verbose : true } ,
223
221
) ;
224
- const logs = getLogMessages ( ui ( ) . logger ) ;
225
- expect ( logs [ 0 ] ) . toContain (
222
+ expect ( ui ( ) ) . toHaveNthLogged (
223
+ 1 ,
224
+ 'warn' ,
226
225
'The --skipPlugins argument references a skipped plugin: p1.' ,
227
226
) ;
227
+ expect ( ui ( ) ) . toHaveNthLogged (
228
+ 2 ,
229
+ 'info' ,
230
+ 'The --skipPlugins argument removed the following categories: c1.' ,
231
+ ) ;
228
232
} ) ;
229
233
} ) ;
230
234
@@ -446,7 +450,6 @@ describe('validateSkippedCategories', () => {
446
450
] as NonNullable < Filterables [ 'categories' ] > ;
447
451
448
452
it ( 'should log info when categories are removed' , ( ) => {
449
- const loggerSpy = vi . spyOn ( ui ( ) . logger , 'info' ) ;
450
453
validateSkippedCategories (
451
454
categories ,
452
455
[
@@ -457,7 +460,8 @@ describe('validateSkippedCategories', () => {
457
460
] as NonNullable < Filterables [ 'categories' ] > ,
458
461
true ,
459
462
) ;
460
- expect ( loggerSpy ) . toHaveBeenCalledWith (
463
+ expect ( ui ( ) ) . toHaveLogged (
464
+ 'info' ,
461
465
'Category c1 was removed because all its refs were skipped. Affected refs: g1 (group)' ,
462
466
) ;
463
467
} ) ;
0 commit comments