Skip to content

Commit 3b16810

Browse files
author
John Doe
committed
Merge branch 'main' into chore/add-zod2md-nx-plugin
2 parents 14649d8 + d1e8192 commit 3b16810

27 files changed

+90
-287
lines changed

packages/plugin-coverage/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@code-pushup/models": "0.96.1",
3838
"@code-pushup/utils": "0.96.1",
3939
"parse-lcov": "^1.0.4",
40-
"yargs": "^17.7.2",
4140
"zod": "^4.0.5"
4241
},
4342
"peerDependencies": {

packages/plugin-coverage/src/bin.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { createRequire } from 'node:module';
2-
import path from 'node:path';
3-
import { fileURLToPath } from 'node:url';
42
import {
53
type Audit,
64
type Group,
@@ -13,7 +11,7 @@ import {
1311
type CoverageType,
1412
coveragePluginConfigSchema,
1513
} from './config.js';
16-
import { createRunnerConfig } from './runner/index.js';
14+
import { createRunnerFunction } from './runner/runner.js';
1715
import { coverageDescription, coverageTypeWeightMapper } from './utils.js';
1816

1917
/**
@@ -60,12 +58,6 @@ export async function coveragePlugin(
6058
})),
6159
};
6260

63-
const runnerScriptPath = path.join(
64-
fileURLToPath(path.dirname(import.meta.url)),
65-
'..',
66-
'bin.js',
67-
);
68-
6961
const packageJson = createRequire(import.meta.url)(
7062
'../../package.json',
7163
) as typeof import('../../package.json');
@@ -82,7 +74,7 @@ export async function coveragePlugin(
8274
version: packageJson.version,
8375
audits,
8476
groups: [group],
85-
runner: await createRunnerConfig(runnerScriptPath, coverageConfig),
77+
runner: createRunnerFunction(coverageConfig),
8678
...(scoreTargets && { scoreTargets }),
8779
};
8880
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import path from 'node:path';
22
import { describe, expect, it } from 'vitest';
3-
import { type RunnerConfig, pluginConfigSchema } from '@code-pushup/models';
3+
import { pluginConfigSchema } from '@code-pushup/models';
44
import { coveragePlugin } from './coverage-plugin.js';
55

6-
vi.mock('./runner/index.ts', () => ({
7-
createRunnerConfig: vi.fn().mockReturnValue({
8-
command: 'node',
9-
outputFile: 'runner-output.json',
10-
} satisfies RunnerConfig),
11-
}));
12-
136
describe('coveragePlugin', () => {
147
const LCOV_PATH = path.join(
158
'packages',
@@ -30,7 +23,7 @@ describe('coveragePlugin', () => {
3023
title: 'Code coverage',
3124
audits: expect.any(Array),
3225
groups: expect.any(Array),
33-
runner: expect.any(Object),
26+
runner: expect.any(Function),
3427
}),
3528
);
3629
});

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

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,12 @@
11
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
33
import { expect } from 'vitest';
4-
import type { AuditOutputs, RunnerConfig } from '@code-pushup/models';
5-
import { createRunnerFiles, readJsonFile } from '@code-pushup/utils';
6-
import type { FinalCoveragePluginConfig } from '../config.js';
7-
import { createRunnerConfig, executeRunner } from './index.js';
4+
import { type AuditOutputs, DEFAULT_PERSIST_CONFIG } from '@code-pushup/models';
5+
import { createRunnerFunction } from './runner.js';
86

9-
describe('createRunnerConfig', () => {
10-
it('should create a valid runner config', async () => {
11-
const runnerConfig = await createRunnerConfig('executeRunner.ts', {
12-
reports: ['coverage/lcov.info'],
13-
coverageTypes: ['branch'],
14-
scoreTargets: 0.85,
15-
continueOnCommandFail: true,
16-
});
17-
expect(runnerConfig).toStrictEqual<RunnerConfig>({
18-
command: 'node',
19-
args: [
20-
'"executeRunner.ts"',
21-
expect.stringContaining('plugin-config.json'),
22-
expect.stringContaining('runner-output.json'),
23-
],
24-
outputFile: expect.stringContaining('runner-output.json'),
25-
configFile: expect.stringContaining('plugin-config.json'),
26-
});
27-
});
28-
29-
it('should provide plugin config to runner in JSON file', async () => {
30-
const pluginConfig: FinalCoveragePluginConfig = {
31-
coverageTypes: ['line'],
32-
reports: ['coverage/lcov.info'],
33-
coverageToolCommand: { command: 'npm', args: ['run', 'test'] },
34-
scoreTargets: 0.85,
35-
continueOnCommandFail: true,
36-
};
37-
38-
const { configFile } = await createRunnerConfig(
39-
'executeRunner.ts',
40-
pluginConfig,
41-
);
42-
43-
expect(configFile).toMatch(/.*plugin-config\.json$/);
44-
const config = await readJsonFile<FinalCoveragePluginConfig>(configFile!);
45-
expect(config).toStrictEqual(pluginConfig);
46-
});
47-
});
48-
49-
describe('executeRunner', () => {
7+
describe('createRunnerFunction', () => {
508
it('should successfully execute runner', async () => {
51-
const config: FinalCoveragePluginConfig = {
9+
const runner = createRunnerFunction({
5210
reports: [
5311
path.join(
5412
fileURLToPath(path.dirname(import.meta.url)),
@@ -61,18 +19,11 @@ describe('executeRunner', () => {
6119
],
6220
coverageTypes: ['line'],
6321
continueOnCommandFail: true,
64-
};
65-
66-
const runnerFiles = await createRunnerFiles(
67-
'coverage',
68-
JSON.stringify(config),
69-
);
70-
await executeRunner(runnerFiles);
22+
});
7123

72-
const results = await readJsonFile<AuditOutputs>(
73-
runnerFiles.runnerOutputPath,
74-
);
75-
expect(results).toStrictEqual<AuditOutputs>([
24+
await expect(
25+
runner({ persist: DEFAULT_PERSIST_CONFIG }),
26+
).resolves.toStrictEqual([
7627
{
7728
slug: 'line-coverage',
7829
score: 0.7,
@@ -112,6 +63,6 @@ describe('executeRunner', () => {
11263
],
11364
},
11465
},
115-
]);
66+
] satisfies AuditOutputs);
11667
});
11768
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { RunnerFunction } from '@code-pushup/models';
2+
import { executeProcess } from '@code-pushup/utils';
3+
import type { FinalCoveragePluginConfig } from '../config.js';
4+
import { lcovResultsToAuditOutputs } from './lcov/lcov-runner.js';
5+
6+
export function createRunnerFunction(
7+
config: FinalCoveragePluginConfig,
8+
): RunnerFunction {
9+
return async () => {
10+
const {
11+
reports,
12+
coverageToolCommand,
13+
continueOnCommandFail,
14+
coverageTypes,
15+
} = config;
16+
17+
// Run coverage tool if provided
18+
if (coverageToolCommand != null) {
19+
const { command, args } = coverageToolCommand;
20+
try {
21+
await executeProcess({ command, args });
22+
} catch {
23+
if (!continueOnCommandFail) {
24+
throw new Error(
25+
'Coverage plugin: Running coverage tool failed. Make sure all your provided tests are passing.',
26+
);
27+
}
28+
}
29+
}
30+
31+
// Calculate coverage from LCOV results
32+
return lcovResultsToAuditOutputs(reports, coverageTypes);
33+
};
34+
}

packages/plugin-eslint/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ export {
1010
eslintConfigFromNxProject,
1111
eslintConfigFromNxProjectAndDeps,
1212
eslintConfigFromNxProjects,
13-
} from './lib/nx/index.js';
13+
} from './lib/nx/nx.js';

packages/plugin-eslint/src/lib/eslint-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
eslintPluginOptionsSchema,
88
} from './config.js';
99
import { ESLINT_PLUGIN_SLUG, ESLINT_PLUGIN_TITLE } from './constants.js';
10-
import { listAuditsAndGroups } from './meta/index.js';
11-
import { createRunnerFunction } from './runner/index.js';
10+
import { listAuditsAndGroups } from './meta/list.js';
11+
import { createRunnerFunction } from './runner/runner.js';
1212

1313
/**
1414
* Instantiates Code PushUp ESLint plugin for use in core config.

packages/plugin-eslint/src/lib/eslint-plugin.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pluginConfigSchema } from '@code-pushup/models';
22
import { eslintPlugin } from './eslint-plugin.js';
3-
import * as metaModule from './meta/index.js';
3+
import * as metaModule from './meta/list.js';
44

55
describe('eslintPlugin', () => {
66
const listAuditsAndGroupsSpy = vi.spyOn(metaModule, 'listAuditsAndGroups');

0 commit comments

Comments
 (0)