-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrunner.integration.test.ts
80 lines (72 loc) · 2.49 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
import { writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, it } from 'vitest';
import { AuditOutput, AuditOutputs, RunnerConfig } from '@code-pushup/models';
import { readJsonFile, removeDirectoryIfExists } from '@code-pushup/utils';
import { createRunnerConfig, executeRunner } from '.';
import { FinalCoveragePluginConfig } from '../config';
import { PLUGIN_CONFIG_PATH, RUNNER_OUTPUT_PATH, WORKDIR } from './constants';
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({
command: 'node',
args: ['executeRunner.ts'],
outputTransform: expect.any(Function),
outputFile: expect.stringContaining('runner-output.json'),
} satisfies RunnerConfig);
});
it('should provide plugin config to runner in JSON file', async () => {
await removeDirectoryIfExists(WORKDIR);
const pluginConfig: FinalCoveragePluginConfig = {
coverageTypes: ['line'],
reports: ['coverage/lcov.info'],
coverageToolCommand: { command: 'npm', args: ['run', 'test'] },
perfectScoreThreshold: 85,
};
await createRunnerConfig('executeRunner.ts', pluginConfig);
const config = await readJsonFile<FinalCoveragePluginConfig>(
PLUGIN_CONFIG_PATH,
);
expect(config).toStrictEqual(pluginConfig);
});
});
describe('executeRunner', () => {
it('should successfully execute runner', async () => {
const config: FinalCoveragePluginConfig = {
reports: [
join(
fileURLToPath(dirname(import.meta.url)),
'..',
'..',
'..',
'mocks',
'single-record-lcov.info',
),
],
coverageTypes: ['line'],
};
await writeFile(PLUGIN_CONFIG_PATH, JSON.stringify(config));
await executeRunner();
const results = await readJsonFile<AuditOutputs>(RUNNER_OUTPUT_PATH);
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),
]);
});
});