-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconfig.unit.test.ts
98 lines (89 loc) · 2.79 KB
/
config.unit.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
93
94
95
96
97
98
import { describe, expect, it } from 'vitest';
import {
CoveragePluginConfig,
CoverageType,
coveragePluginConfigSchema,
} from './config';
describe('coveragePluginConfigSchema', () => {
it('accepts a code coverage configuration with all entities', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: ['branch', 'function'],
reports: [
{
resultsPath: 'coverage/cli/lcov.info',
pathToProject: 'packages/cli',
},
],
coverageToolCommand: {
command: 'npx nx run-many',
args: ['-t', 'test', '--coverage'],
},
perfectScoreThreshold: 0.85,
} satisfies CoveragePluginConfig),
).not.toThrow();
});
it('accepts a minimal code coverage configuration', () => {
expect(() =>
coveragePluginConfigSchema.parse({
reports: ['coverage/cli/lcov.info'],
} satisfies CoveragePluginConfig),
).not.toThrow();
});
it('replaces undefined coverage with all available types', () => {
const config = {
reports: ['coverage/cli/lcov.info'],
} satisfies CoveragePluginConfig;
expect(() => coveragePluginConfigSchema.parse(config)).not.toThrow();
const { coverageTypes } = coveragePluginConfigSchema.parse(config);
expect(coverageTypes).toEqual([
'function',
'branch',
'line',
] satisfies CoverageType[]);
});
it('throws for empty coverage type array', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: [],
reports: ['coverage/cli/lcov.info'],
} satisfies CoveragePluginConfig),
).toThrow('too_small');
});
it('throws for no report', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: ['branch'],
reports: [],
} satisfies CoveragePluginConfig),
).toThrow('too_small');
});
it('throws for unsupported report format', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: ['line'],
reports: ['coverage/cli/coverage-final.json'],
} satisfies CoveragePluginConfig),
).toThrow(/Invalid input: must include.+lcov/);
});
it('throws for missing command', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: ['line'],
reports: ['coverage/cli/lcov.info'],
coverageToolCommand: {
args: ['npx', 'nx', 'run-many', '-t', 'test', '--coverage'],
},
}),
).toThrow('invalid_type');
});
it('throws for invalid score threshold', () => {
expect(() =>
coveragePluginConfigSchema.parse({
coverageTypes: ['line'],
reports: ['coverage/cli/lcov.info'],
perfectScoreThreshold: 1.1,
} satisfies CoveragePluginConfig),
).toThrow('too_big');
});
});