@@ -264,7 +264,7 @@ describe('toIssues', () => {
264264 files : new Set ( [
265265 '/User/projects/code-pushup-cli/packages/utils/src/index.js' ,
266266 ] ) ,
267- } ) ,
267+ } as KnipIssues ) ,
268268 ) . resolves . toStrictEqual ( [
269269 expect . objectContaining ( {
270270 message : expect . stringMatching ( 'Unused file' ) ,
@@ -294,10 +294,10 @@ describe('toIssues', () => {
294294 '/User/projects/code-pushup-cli/packages/utils/src/index.js' ,
295295 symbol : 'CliUi' ,
296296 severity : 'error' ,
297- } ,
297+ } as unknown as KnipIssue ,
298298 } ,
299299 } ,
300- } ) ,
300+ } as unknown as KnipIssues ) ,
301301 ) . resolves . toStrictEqual ( [
302302 expect . objectContaining ( {
303303 message : expect . stringMatching ( 'CliUi' ) ,
@@ -312,59 +312,88 @@ describe('toIssues', () => {
312312
313313describe ( 'knipToCpReport' , ( ) => {
314314 it ( 'should return empty audits if no report is flagged positive' , async ( ) => {
315- await expect (
316- knipToCpReport ( {
317- issues : { } ,
318- } as ReporterOptions ) ,
319- ) . resolves . toStrictEqual ( [ ] ) ;
315+ const result = await knipToCpReport ( {
316+ issues : { } ,
317+ report : { } ,
318+ } as ReporterOptions ) ;
319+
320+ expect ( result ) . toEqual (
321+ expect . arrayContaining ( [ expect . objectContaining ( { score : 0 , value : 0 } ) ] ) ,
322+ ) ;
320323 } ) ;
321324
322325 it ( 'should return only audits flagged in report object' , async ( ) => {
323- await expect (
324- knipToCpReport ( {
325- issues : {
326- dependencies : { } ,
327- } ,
328- } as ReporterOptions ) ,
329- ) . resolves . toStrictEqual (
326+ const result = await knipToCpReport ( {
327+ issues : {
328+ dependencies : { } ,
329+ } ,
330+ report : { dependencies : true } ,
331+ } as ReporterOptions ) ;
332+
333+ expect ( result ) . toEqual (
330334 expect . arrayContaining ( [
331335 expect . objectContaining ( { slug : 'dependencies' } ) ,
332336 ] ) ,
333337 ) ;
334338 } ) ;
335339
340+ it ( 'should return readable audit slug derived from knip issueType' , async ( ) => {
341+ const result = await knipToCpReport ( {
342+ issues : {
343+ optionalPeerDependencies : { } ,
344+ } ,
345+ report : { optionalPeerDependencies : true } ,
346+ } as ReporterOptions ) ;
347+
348+ expect ( result ) . toEqual (
349+ expect . arrayContaining ( [
350+ expect . objectContaining ( { slug : 'optional-peer-dependencies' } ) ,
351+ ] ) ,
352+ ) ;
353+ } ) ;
354+
336355 it ( 'should return audit result with number of issues as value' , async ( ) => {
337- await expect (
338- knipToCpReport ( {
339- issues : { files : new Set ( [ 'a.js' , 'b.js' , 'c.js' ] ) } ,
340- } as ReporterOptions ) ,
341- ) . resolves . toStrictEqual ( [ expect . objectContaining ( { value : 3 } ) ] ) ;
356+ const result = await knipToCpReport ( {
357+ issues : { files : new Set ( [ 'a.js' , 'b.js' , 'c.js' ] ) } ,
358+ report : { files : true } ,
359+ } as ReporterOptions ) ;
360+
361+ expect ( result ) . toEqual (
362+ expect . arrayContaining ( [
363+ expect . objectContaining ( { slug : 'files' , value : 3 } ) ,
364+ ] ) ,
365+ ) ;
342366 } ) ;
343367
344368 it ( 'should return audit result without display value' , async ( ) => {
345- await expect (
346- knipToCpReport ( {
347- issues : { files : new Set ( [ 'main.js' ] ) } ,
348- } as ReporterOptions ) ,
349- ) . resolves . toStrictEqual ( [
350- expect . not . objectContaining ( { displayValue : expect . any ( String ) } ) ,
351- ] ) ;
369+ const result = await knipToCpReport ( {
370+ issues : { files : new Set ( [ 'main.js' ] ) } ,
371+ report : { files : true } ,
372+ } as ReporterOptions ) ;
373+
374+ // Check that the files audit doesn't have displayValue
375+ const filesAudit = result . find ( ( audit ) => audit . slug === 'files' ) ;
376+ expect ( filesAudit ) . not . toHaveProperty ( 'displayValue' ) ;
352377 } ) ;
353378
354379 it ( 'should score audits with empty issues with 1' , async ( ) => {
355- await expect (
356- knipToCpReport ( {
357- issues : { files : new Set ( ) } ,
358- } as ReporterOptions ) ,
359- ) . resolves . toStrictEqual ( [ expect . objectContaining ( { score : 1 } ) ] ) ;
380+ const result = await knipToCpReport ( {
381+ issues : { files : new Set ( ) } ,
382+ report : { files : true } ,
383+ } as ReporterOptions ) ;
384+
385+ const filesAudit = result . find ( ( audit ) => audit . slug === 'files' ) ;
386+ expect ( filesAudit ) . toEqual ( expect . objectContaining ( { score : 1 , value : 0 } ) ) ;
360387 } ) ;
361388
362389 it ( 'should score audits with issues with 0' , async ( ) => {
363- await expect (
364- knipToCpReport ( {
365- issues : { files : new Set ( [ 'main.js' ] ) } ,
366- } as ReporterOptions ) ,
367- ) . resolves . toStrictEqual ( [ expect . objectContaining ( { score : 0 } ) ] ) ;
390+ const result = await knipToCpReport ( {
391+ issues : { files : new Set ( [ 'main.js' ] ) } ,
392+ report : { files : true } ,
393+ } as ReporterOptions ) ;
394+
395+ const filesAudit = result . find ( ( audit ) => audit . slug === 'files' ) ;
396+ expect ( filesAudit ) . toEqual ( expect . objectContaining ( { score : 0 , value : 1 } ) ) ;
368397 } ) ;
369398
370399 it ( 'should return valid outputs schema' , async ( ) => {
@@ -384,7 +413,7 @@ describe('knipToCpReport', () => {
384413 col : 0 ,
385414 symbols : [ ] ,
386415 parentSymbol : '' ,
387- } ,
416+ } as unknown as KnipIssue ,
388417 } ,
389418 '/User/username/code-pushup-cli/examples/plugins/.eslintrc.json' : {
390419 'jsonc-eslint-parser' : {
@@ -393,11 +422,12 @@ describe('knipToCpReport', () => {
393422 filePath :
394423 '/User/username/code-pushup-cli/packages/utils/package.json' ,
395424 severity : 'error' ,
396- } ,
425+ } as unknown as KnipIssue ,
397426 } ,
398427 } as IssueRecords ,
399428 } as ReporterOptions [ 'issues' ] ,
400- } ) ;
429+ report : { files : true , unlisted : true } ,
430+ } as ReporterOptions ) ;
401431 expect ( ( ) => auditOutputsSchema . parse ( result ) ) . not . toThrowError ( ) ;
402432 } ) ;
403433} ) ;
0 commit comments