Skip to content

Commit 774f3a6

Browse files
committed
chore(plugin-coverage): use universal paths in tests, fix lint
1 parent 5701d09 commit 774f3a6

File tree

7 files changed

+38
-36
lines changed

7 files changed

+38
-36
lines changed

e2e/cli-e2e/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"extends": ["../../.eslintrc.json"],
3-
"ignorePatterns": ["!**/*", "code-pushup.config.*?.ts"],
3+
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
44
"overrides": [
55
{
66
"files": ["*.ts", "*.tsx"],

e2e/cli-e2e/tests/collect.e2e.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { join } from 'node:path';
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23
import { PluginReport, Report, reportSchema } from '@code-pushup/models';
34
import { cleanTestFolder } from '@code-pushup/testing-utils';
45
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
@@ -52,8 +53,8 @@ describe('CLI collect', () => {
5253
*/
5354

5455
const configPath = join(
55-
'e2e',
56-
'cli-e2e',
56+
fileURLToPath(dirname(import.meta.url)),
57+
'..',
5758
'mocks',
5859
'fixtures',
5960
'code-pushup.config.coverage.ts',

packages/models/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,27 @@ export {
1919
} from './lib/core-config';
2020
export { Group, GroupRef, groupSchema } from './lib/group';
2121
export {
22-
MAX_DESCRIPTION_LENGTH,
23-
MAX_ISSUE_MESSAGE_LENGTH,
24-
MAX_SLUG_LENGTH,
25-
MAX_TITLE_LENGTH,
26-
} from './lib/implementation/limits';
22+
CONFIG_FILE_NAME,
23+
SUPPORTED_CONFIG_FILE_FORMATS,
24+
} from './lib/implementation/configuration';
2725
export {
2826
PERSIST_FILENAME,
29-
PERSIST_OUTPUT_DIR,
3027
PERSIST_FORMAT,
28+
PERSIST_OUTPUT_DIR,
3129
} from './lib/implementation/constants';
3230
export {
33-
CONFIG_FILE_NAME,
34-
SUPPORTED_CONFIG_FILE_FORMATS,
35-
} from './lib/implementation/configuration';
31+
MAX_DESCRIPTION_LENGTH,
32+
MAX_ISSUE_MESSAGE_LENGTH,
33+
MAX_SLUG_LENGTH,
34+
MAX_TITLE_LENGTH,
35+
} from './lib/implementation/limits';
3636
export {
3737
fileNameSchema,
3838
filePathSchema,
3939
materialIconSchema,
4040
urlSchema,
4141
} from './lib/implementation/schemas';
42+
export { exists } from './lib/implementation/utils';
4243
export {
4344
Format,
4445
PersistConfig,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { join } from 'node:path';
1+
import { dirname, join } from 'node:path';
2+
import { fileURLToPath } from 'node:url';
23
import { describe, it } from 'vitest';
34
import { lcovResultsToAuditOutputs } from './runner';
45

@@ -14,8 +15,11 @@ describe('lcovResultsToAuditOutputs', () => {
1415
[
1516
{
1617
resultsPath: join(
17-
'packages',
18-
'plugin-coverage',
18+
fileURLToPath(dirname(import.meta.url)),
19+
'..',
20+
'..',
21+
'..',
22+
'..',
1923
'mocks',
2024
'single-record-lcov.info',
2125
),

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import { join } from 'node:path';
22
import type { LCOVRecord } from 'parse-lcov';
33
import { AuditOutputs } from '@code-pushup/models';
4-
import { readTextFile, toUnixPath } from '@code-pushup/utils';
5-
//TODO fix, why doesnt it know the exists import??
6-
import { exists } from '../../../../../models/src/lib/implementation/utils';
4+
import { exists, readTextFile } from '@code-pushup/utils';
75
import { CoverageReport, CoverageType } from '../../config';
86
import { parseLcov } from './parse-lcov';
97
import {
108
lcovCoverageToAuditOutput,
11-
reportToStatFunctionMapper as recordToStatFunctionMapper,
9+
recordToStatFunctionMapper,
1210
} from './transform';
1311
import { LCOVStat, LCOVStats } from './types';
1412

@@ -26,20 +24,19 @@ export async function lcovResultsToAuditOutputs(
2624
coverageTypes: CoverageType[],
2725
): Promise<AuditOutputs> {
2826
const parsedReports = await Promise.all(
29-
reports.map(report =>
30-
readTextFile(toUnixPath(report.resultsPath))
31-
.then(reportContent => parseLcov(reportContent))
32-
.then(records =>
33-
records.map<LCOVRecord>(record => ({
34-
...record,
35-
file:
36-
report.pathToProject == null
37-
? record.file
38-
: join(report.pathToProject, record.file),
39-
})),
40-
),
41-
),
27+
reports.map(async report => {
28+
const reportContent = await readTextFile(report.resultsPath);
29+
const parsedRecords = parseLcov(reportContent);
30+
return parsedRecords.map<LCOVRecord>(record => ({
31+
...record,
32+
file:
33+
report.pathToProject == null
34+
? record.file
35+
: join(report.pathToProject, record.file),
36+
}));
37+
}),
4238
);
39+
4340
if (parsedReports.length !== reports.length) {
4441
throw new Error('Some provided LCOV reports were not valid.');
4542
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable max-lines-per-function */
21
import { LCOVRecord } from 'parse-lcov';
32
import { AuditOutput, Issue } from '@code-pushup/models';
43
import { toUnixPath } from '@code-pushup/utils';
@@ -88,7 +87,7 @@ export function lcovReportToBranchStat(record: LCOVRecord): LCOVStat {
8887
};
8988
}
9089

91-
export const reportToStatFunctionMapper = {
90+
export const recordToStatFunctionMapper = {
9291
branch: lcovReportToBranchStat,
9392
line: lcovReportToLineStat,
9493
function: lcovReportToFunctionStat,

packages/utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { exists } from '@code-pushup/models';
12
export {
23
ProcessConfig,
34
ProcessError,
@@ -56,7 +57,6 @@ export {
5657
CliArgsObject,
5758
countOccurrences,
5859
distinct,
59-
exists,
6060
factorOf,
6161
objectToCliArgs,
6262
objectToEntries,

0 commit comments

Comments
 (0)