Skip to content

Commit 3195da2

Browse files
committed
fix(plugin-coverage): convert new lines on Windows for parse-lcov, update docs
1 parent 349c772 commit 3195da2

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

packages/plugin-coverage/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Measured coverage types are mapped to Code PushUp audits in the following way
3333
plugins: [
3434
// ...
3535
await coveragePlugin({
36-
reports: [{ resultsPath: 'coverage/cli/lcov.info', pathToProject: 'packages/cli' }],
36+
reports: [{ resultsPath: 'coverage/lcov.info' }],
3737
coverageToolCommand: {
3838
command: 'npx',
3939
args: ['jest', '--coverage', '--coverageReporters=lcov'],

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'node:path';
22
import type { LCOVRecord } from 'parse-lcov';
33
import { AuditOutputs } from '@code-pushup/models';
4-
import { exists, readTextFile } from '@code-pushup/utils';
4+
import { exists, readTextFile, toUnixNewlines } from '@code-pushup/utils';
55
import { CoverageReport, CoverageType } from '../../config';
66
import { parseLcov } from './parse-lcov';
77
import {
@@ -26,7 +26,7 @@ export async function lcovResultsToAuditOutputs(
2626
const parsedReports = await Promise.all(
2727
reports.map(async report => {
2828
const reportContent = await readTextFile(report.resultsPath);
29-
const parsedRecords = parseLcov(reportContent);
29+
const parsedRecords = parseLcov(toUnixNewlines(reportContent));
3030
return parsedRecords.map<LCOVRecord>(record => ({
3131
...record,
3232
file:
@@ -36,7 +36,6 @@ export async function lcovResultsToAuditOutputs(
3636
}));
3737
}),
3838
);
39-
4039
if (parsedReports.length !== reports.length) {
4140
throw new Error('Some provided LCOV reports were not valid.');
4241
}

packages/utils/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export {
6565
toArray,
6666
toNumberPrecision,
6767
toOrdinal,
68+
toUnixNewlines,
6869
toUnixPath,
6970
} from './lib/transform';
7071
export { verboseUtils } from './lib/verbose-utils';

packages/utils/src/lib/transform.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { platform } from 'node:os';
2+
13
export function toArray<T>(val: T | T[]): T[] {
24
return Array.isArray(val) ? val : [val];
35
}
@@ -116,6 +118,10 @@ export function toUnixPath(
116118
return unixPath;
117119
}
118120

121+
export function toUnixNewlines(text: string): string {
122+
return platform() === 'win32' ? text.replace(/\r\n/g, '\n') : text;
123+
}
124+
119125
export function capitalize<T extends string>(text: T): Capitalize<T> {
120126
return `${text.charAt(0).toLocaleUpperCase()}${text.slice(
121127
1,

0 commit comments

Comments
 (0)