MCPcopy Create free account
hub / github.com/code-pushup/cli / getNxCoveragePaths

Function getNxCoveragePaths

packages/plugin-coverage/src/lib/nx/coverage-paths.ts:24–73  ·  view source on GitHub ↗
(
  targets: string[] = ['test'],
)

Source from the content-addressed store, hash-verified

22 * @returns An array of coverage result information for the coverage plugin.
23 */
24export async function getNxCoveragePaths(
25 targets: string[] = ['test'],
26): Promise<CoverageResult[]> {
27 const { nodes } = await loadNxProjectGraph();
28
29 const coverageResultsPerTarget = Object.fromEntries(
30 await Promise.all(
31 targets.map(async (target): Promise<[string, CoverageResult[]]> => {
32 const relevantNodes = Object.values(nodes).filter(graph =>
33 hasNxTarget(graph, target),
34 );
35
36 return [
37 target,
38 await Promise.all(
39 relevantNodes.map(({ data }) =>
40 getCoveragePathsForTarget(data, target),
41 ),
42 ),
43 ];
44 }),
45 ),
46 );
47
48 const coverageResults = Object.values(coverageResultsPerTarget).flat();
49
50 logger.info(
51 formatMetaLog(
52 `Inferred ${pluralizeToken('coverage report', coverageResults.length)} from Nx projects with ${pluralize('target', targets.length)} ${
53 targets.length === 1
54 ? targets[0]
55 : Object.entries(coverageResultsPerTarget)
56 .map(([target, results]) => `${target} (${results.length})`)
57 .join(' and ')
58 }`,
59 ),
60 );
61 logger.debug(
62 formatMetaLog(
63 coverageResults
64 .map(
65 result =>
66 `• ${typeof result === 'string' ? result : result.resultsPath}`,
67 )
68 .join('\n'),
69 ),
70 );
71
72 return coverageResults;
73}
74
75function hasNxTarget(
76 project: ProjectGraphProjectNode,

Callers 1

configureCoveragePluginFunction · 0.85

Calls 7

loadNxProjectGraphFunction · 0.90
pluralizeTokenFunction · 0.90
pluralizeFunction · 0.90
hasNxTargetFunction · 0.85
infoMethod · 0.80
debugMethod · 0.45

Tested by

no test coverage detected