Skip to content

Commit 0292c9f

Browse files
committed
feat(plugin-coverage): replace @poppinss/cliui with new logger
1 parent 83b9b7b commit 0292c9f

File tree

5 files changed

+10
-37
lines changed

5 files changed

+10
-37
lines changed

packages/plugin-coverage/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"dependencies": {
3737
"@code-pushup/models": "0.85.0",
3838
"@code-pushup/utils": "0.85.0",
39-
"ansis": "^3.3.0",
4039
"parse-lcov": "^1.0.4",
4140
"yargs": "^17.7.2",
4241
"zod": "^4.0.5"

packages/plugin-coverage/src/lib/nx/coverage-paths.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import type {
66
} from '@nx/devkit';
77
import type { JestExecutorOptions } from '@nx/jest/src/executors/jest/schema';
88
import type { VitestExecutorOptions } from '@nx/vite/executors';
9-
import { bold } from 'ansis';
109
import path from 'node:path';
11-
import { importModule, stringifyError, ui } from '@code-pushup/utils';
10+
import { importModule, logger, stringifyError } from '@code-pushup/utils';
1211
import type { CoverageResult } from '../config.js';
1312

1413
/**
@@ -22,7 +21,7 @@ async function resolveCachedProjectGraph() {
2221
try {
2322
return readCachedProjectGraph();
2423
} catch (error) {
25-
ui().logger.info(
24+
logger.info(
2625
`Could not read cached project graph, falling back to async creation.
2726
${stringifyError(error)}`,
2827
);
@@ -36,13 +35,8 @@ async function resolveCachedProjectGraph() {
3635
*/
3736
export async function getNxCoveragePaths(
3837
targets: string[] = ['test'],
39-
verbose?: boolean,
4038
): Promise<CoverageResult[]> {
41-
if (verbose) {
42-
ui().logger.info(
43-
bold('💡 Gathering coverage from the following nx projects:'),
44-
);
45-
}
39+
logger.debug('💡 Gathering coverage from the following nx projects:');
4640

4741
const { nodes } = await resolveCachedProjectGraph();
4842

@@ -55,18 +49,14 @@ export async function getNxCoveragePaths(
5549
return await Promise.all(
5650
relevantNodes.map<Promise<CoverageResult>>(async ({ name, data }) => {
5751
const coveragePaths = await getCoveragePathsForTarget(data, target);
58-
if (verbose) {
59-
ui().logger.info(`- ${name}: ${target}`);
60-
}
52+
logger.debug(`- ${name}: ${target}`);
6153
return coveragePaths;
6254
}),
6355
);
6456
}),
6557
);
6658

67-
if (verbose) {
68-
ui().logger.info('\n');
69-
}
59+
logger.debug('');
7060

7161
return coverageResults.flat();
7262
}

packages/plugin-coverage/src/lib/runner/index.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import { bold } from 'ansis';
21
import { writeFile } from 'node:fs/promises';
32
import path from 'node:path';
43
import type { RunnerConfig, RunnerFilesPaths } from '@code-pushup/models';
54
import {
6-
ProcessError,
75
createRunnerFiles,
86
ensureDirectoryExists,
97
executeProcess,
108
filePathToCliArg,
119
objectToCliArgs,
1210
readJsonFile,
13-
ui,
1411
} from '@code-pushup/utils';
1512
import type { FinalCoveragePluginConfig } from '../config.js';
1613
import { lcovResultsToAuditOutputs } from './lcov/lcov-runner.js';
@@ -28,16 +25,6 @@ export async function executeRunner({
2825
try {
2926
await executeProcess({ command, args });
3027
} catch (error) {
31-
if (error instanceof ProcessError) {
32-
const loggingFn = continueOnCommandFail
33-
? ui().logger.warning.bind(ui().logger)
34-
: ui().logger.error.bind(ui().logger);
35-
loggingFn(bold('stdout from failed coverage tool process:'));
36-
loggingFn(error.stdout);
37-
loggingFn(bold('stderr from failed coverage tool process:'));
38-
loggingFn(error.stderr);
39-
}
40-
4128
if (!continueOnCommandFail) {
4229
throw new Error(
4330
'Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing.',

packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
type FileCoverage,
66
exists,
77
getGitRoot,
8+
logger,
89
objectFromEntries,
910
objectToEntries,
1011
readTextFile,
1112
toUnixNewlines,
12-
ui,
1313
} from '@code-pushup/utils';
1414
import type { CoverageResult, CoverageType } from '../../config.js';
1515
import { mergeLcovResults } from './merge-lcov.js';
@@ -72,9 +72,7 @@ export async function parseLcovFiles(
7272
typeof result === 'string' ? result : result.resultsPath;
7373
const lcovFileContent = await readTextFile(resultsPath);
7474
if (lcovFileContent.trim() === '') {
75-
ui().logger.warning(
76-
`Coverage plugin: Empty lcov report file detected at ${resultsPath}.`,
77-
);
75+
logger.warn(`Empty lcov report file detected at ${resultsPath}.`);
7876
}
7977
const parsedRecords = parseLcov(toUnixNewlines(lcovFileContent));
8078
return parsedRecords.map(

packages/plugin-coverage/src/lib/runner/lcov/lcov-runner.unit.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { vol } from 'memfs';
22
import path from 'node:path';
33
import { beforeEach, describe, expect, it, vi } from 'vitest';
4-
import { getGitRoot, ui } from '@code-pushup/utils';
4+
import { getGitRoot, logger } from '@code-pushup/utils';
55
import type { CoverageResult, CoverageType } from '../../config.js';
66
import { lcovResultsToAuditOutputs, parseLcovFiles } from './lcov-runner.js';
77

@@ -144,9 +144,8 @@ end_of_record
144144
path.join('coverage', 'lcov.info'),
145145
]);
146146

147-
expect(ui()).toHaveLogged(
148-
'warn',
149-
`Coverage plugin: Empty lcov report file detected at ${path.join(
147+
expect(logger.warn).toHaveBeenCalledWith(
148+
`Empty lcov report file detected at ${path.join(
150149
'coverage',
151150
'lcov.info',
152151
)}.`,

0 commit comments

Comments
 (0)