11import { describe , expect } from 'vitest' ;
22import type { CategoryConfig , PluginConfig } from '@code-pushup/models' ;
3- import { getLogMessages } from '@code-pushup/test-utils' ;
43import { ui } from '@code-pushup/utils' ;
54import type { FilterOptionType , Filterables } from './filter.model.js' ;
65import {
@@ -19,22 +18,22 @@ describe('validateFilterOption', () => {
1918 [
2019 'onlyPlugins' ,
2120 [ '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. ' ,
2322 ] ,
2423 [
2524 'onlyPlugins' ,
2625 [ '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. ' ,
2827 ] ,
2928 [
3029 'onlyCategories' ,
3130 [ '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. ' ,
3332 ] ,
3433 [
3534 'onlyCategories' ,
3635 [ '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. ' ,
3837 ] ,
3938 ] ) (
4039 'should log a warning if the only argument %s references nonexistent slugs %o along with valid ones' ,
@@ -51,31 +50,30 @@ describe('validateFilterOption', () => {
5150 } ,
5251 { itemsToFilter, skippedItems : [ ] , verbose : false } ,
5352 ) ;
54- const logs = getLogMessages ( ui ( ) . logger ) ;
55- expect ( logs [ 0 ] ) . toContain ( expected ) ;
53+ expect ( ui ( ) ) . toHaveLoggedMessage ( expected ) ;
5654 } ,
5755 ) ;
5856
5957 it . each ( [
6058 [
6159 'skipPlugins' ,
6260 [ '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. ' ,
6462 ] ,
6563 [
6664 'skipPlugins' ,
6765 [ '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. ' ,
6967 ] ,
7068 [
7169 'skipCategories' ,
7270 [ '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. ' ,
7472 ] ,
7573 [
7674 'skipCategories' ,
7775 [ '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. ' ,
7977 ] ,
8078 ] ) (
8179 'should log a warning if the skip argument %s references nonexistent slugs %o' ,
@@ -95,8 +93,7 @@ describe('validateFilterOption', () => {
9593 } ,
9694 { itemsToFilter, skippedItems : [ ] , verbose : false } ,
9795 ) ;
98- const logs = getLogMessages ( ui ( ) . logger ) ;
99- expect ( logs [ 0 ] ) . toContain ( expected ) ;
96+ expect ( ui ( ) ) . toHaveLoggedMessage ( expected ) ;
10097 } ,
10198 ) ;
10299
@@ -111,7 +108,7 @@ describe('validateFilterOption', () => {
111108 } ,
112109 { itemsToFilter : [ 'p1' ] , skippedItems : [ ] , verbose : false } ,
113110 ) ;
114- expect ( getLogMessages ( ui ( ) . logger ) ) . toHaveLength ( 0 ) ;
111+ expect ( ui ( ) ) . not . toHaveLogged ( ) ;
115112 } ) ;
116113
117114 it ( 'should log a category ignored as a result of plugin filtering' , ( ) => {
@@ -130,9 +127,9 @@ describe('validateFilterOption', () => {
130127 } ,
131128 { itemsToFilter : [ 'p1' ] , skippedItems : [ ] , verbose : true } ,
132129 ) ;
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 ( ) ) . toHaveLoggedMessage (
132+ 'The --onlyPlugins argument removed the following categories: c1, c3. ' ,
136133 ) ;
137134 } ) ;
138135
@@ -221,10 +218,14 @@ describe('validateFilterOption', () => {
221218 { plugins, categories } ,
222219 { itemsToFilter : [ 'p1' ] , skippedItems : [ 'p1' ] , verbose : true } ,
223220 ) ;
224- const logs = getLogMessages ( ui ( ) . logger ) ;
225- expect ( logs [ 0 ] ) . toContain (
221+ expect ( ui ( ) ) . toHaveLoggedNthMessage (
222+ 1 ,
226223 'The --skipPlugins argument references a skipped plugin: p1.' ,
227224 ) ;
225+ expect ( ui ( ) ) . toHaveLoggedNthMessage (
226+ 2 ,
227+ 'The --skipPlugins argument removed the following categories: c1.' ,
228+ ) ;
228229 } ) ;
229230} ) ;
230231
@@ -446,7 +447,6 @@ describe('validateSkippedCategories', () => {
446447 ] as NonNullable < Filterables [ 'categories' ] > ;
447448
448449 it ( 'should log info when categories are removed' , ( ) => {
449- const loggerSpy = vi . spyOn ( ui ( ) . logger , 'info' ) ;
450450 validateSkippedCategories (
451451 categories ,
452452 [
@@ -457,7 +457,8 @@ describe('validateSkippedCategories', () => {
457457 ] as NonNullable < Filterables [ 'categories' ] > ,
458458 true ,
459459 ) ;
460- expect ( loggerSpy ) . toHaveBeenCalledWith (
460+ expect ( ui ( ) ) . toHaveLoggedLevel ( 'info' ) ;
461+ expect ( ui ( ) ) . toHaveLoggedMessage (
461462 'Category c1 was removed because all its refs were skipped. Affected refs: g1 (group)' ,
462463 ) ;
463464 } ) ;
0 commit comments