-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrunner.integration.test.ts
92 lines (85 loc) · 2.66 KB
/
runner.integration.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect } from 'vitest';
import type {
AuditOutput,
AuditOutputs,
RunnerConfig,
} from '@code-pushup/models';
import { createRunnerFiles, readJsonFile } from '@code-pushup/utils';
import type { FinalCoveragePluginConfig } from '../config.js';
import { createRunnerConfig, executeRunner } from './index.js';
describe('createRunnerConfig', () => {
it('should create a valid runner config', async () => {
const runnerConfig = await createRunnerConfig('executeRunner.ts', {
reports: ['coverage/lcov.info'],
coverageTypes: ['branch'],
perfectScoreThreshold: 85,
});
expect(runnerConfig).toStrictEqual<RunnerConfig>({
command: 'node',
args: [
'"executeRunner.ts"',
expect.stringContaining('plugin-config.json'),
expect.stringContaining('runner-output.json'),
],
outputTransform: expect.any(Function),
outputFile: expect.stringContaining('runner-output.json'),
configFile: expect.stringContaining('plugin-config.json'),
});
});
it('should provide plugin config to runner in JSON file', async () => {
const pluginConfig: FinalCoveragePluginConfig = {
coverageTypes: ['line'],
reports: ['coverage/lcov.info'],
coverageToolCommand: { command: 'npm', args: ['run', 'test'] },
perfectScoreThreshold: 85,
};
const { configFile } = await createRunnerConfig(
'executeRunner.ts',
pluginConfig,
);
expect(configFile).toMatch(/.*plugin-config\.json$/);
const config = await readJsonFile<FinalCoveragePluginConfig>(configFile!);
expect(config).toStrictEqual(pluginConfig);
});
});
describe('executeRunner', () => {
it('should successfully execute runner', async () => {
const config: FinalCoveragePluginConfig = {
reports: [
path.join(
fileURLToPath(path.dirname(import.meta.url)),
'..',
'..',
'..',
'mocks',
'single-record-lcov.info',
),
],
coverageTypes: ['line'],
};
const runnerFiles = await createRunnerFiles(
'coverage',
JSON.stringify(config),
);
await executeRunner(runnerFiles);
const results = await readJsonFile<AuditOutputs>(
runnerFiles.runnerOutputPath,
);
expect(results).toStrictEqual([
expect.objectContaining({
slug: 'line-coverage',
score: 0.7,
value: 70,
details: {
issues: [
expect.objectContaining({
message: 'Lines 7-9 are not covered in any test case.',
}),
],
},
} satisfies AuditOutput),
]);
});
});