@@ -7,8 +7,15 @@ import type {
77import type { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema' ;
88import type { VitestExecutorOptions } from '@nx/vite/executors' ;
99import path from 'node:path' ;
10- import { importModule , logger , stringifyError } from '@code-pushup/utils' ;
10+ import {
11+ importModule ,
12+ logger ,
13+ pluralize ,
14+ pluralizeToken ,
15+ stringifyError ,
16+ } from '@code-pushup/utils' ;
1117import type { CoverageResult } from '../config.js' ;
18+ import { formatMetaLog } from '../format.js' ;
1219
1320/**
1421 * Resolves the cached project graph for the current Nx workspace.
@@ -21,9 +28,8 @@ async function resolveCachedProjectGraph() {
2128 try {
2229 return readCachedProjectGraph ( ) ;
2330 } catch ( error ) {
24- logger . info (
25- `Could not read cached project graph, falling back to async creation.
26- ${ stringifyError ( error ) } ` ,
31+ logger . warn (
32+ `Could not read cached project graph, falling back to async creation - ${ stringifyError ( error ) } ` ,
2733 ) ;
2834 return await createProjectGraphAsync ( { exitOnError : false } ) ;
2935 }
@@ -36,29 +42,52 @@ async function resolveCachedProjectGraph() {
3642export async function getNxCoveragePaths (
3743 targets : string [ ] = [ 'test' ] ,
3844) : Promise < CoverageResult [ ] > {
39- logger . debug ( '💡 Gathering coverage from the following nx projects:' ) ;
40-
4145 const { nodes } = await resolveCachedProjectGraph ( ) ;
4246
43- const coverageResults = await Promise . all (
44- targets . map ( async target => {
45- const relevantNodes = Object . values ( nodes ) . filter ( graph =>
46- hasNxTarget ( graph , target ) ,
47- ) ;
48-
49- return await Promise . all (
50- relevantNodes . map < Promise < CoverageResult > > ( async ( { name, data } ) => {
51- const coveragePaths = await getCoveragePathsForTarget ( data , target ) ;
52- logger . debug ( `- ${ name } : ${ target } ` ) ;
53- return coveragePaths ;
54- } ) ,
55- ) ;
56- } ) ,
47+ const coverageResultsPerTarget = Object . fromEntries (
48+ await Promise . all (
49+ targets . map ( async ( target ) : Promise < [ string , CoverageResult [ ] ] > => {
50+ const relevantNodes = Object . values ( nodes ) . filter ( graph =>
51+ hasNxTarget ( graph , target ) ,
52+ ) ;
53+
54+ return [
55+ target ,
56+ await Promise . all (
57+ relevantNodes . map ( ( { data } ) =>
58+ getCoveragePathsForTarget ( data , target ) ,
59+ ) ,
60+ ) ,
61+ ] ;
62+ } ) ,
63+ ) ,
5764 ) ;
5865
59- logger . debug ( '' ) ;
66+ const coverageResults = Object . values ( coverageResultsPerTarget ) . flat ( ) ;
67+
68+ logger . info (
69+ formatMetaLog (
70+ `Inferred ${ pluralizeToken ( 'coverage report' , coverageResults . length ) } from Nx projects with ${ pluralize ( 'target' , targets . length ) } ${
71+ targets . length === 1
72+ ? targets [ 0 ]
73+ : Object . entries ( coverageResultsPerTarget )
74+ . map ( ( [ target , results ] ) => `${ target } (${ results . length } )` )
75+ . join ( ' and ' )
76+ } `,
77+ ) ,
78+ ) ;
79+ logger . debug (
80+ formatMetaLog (
81+ coverageResults
82+ . map (
83+ result =>
84+ `• ${ typeof result === 'string' ? result : result . resultsPath } ` ,
85+ )
86+ . join ( '\n' ) ,
87+ ) ,
88+ ) ;
6089
61- return coverageResults . flat ( ) ;
90+ return coverageResults ;
6291}
6392
6493function hasNxTarget (
0 commit comments