-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcore-config.unit.test.ts
More file actions
201 lines (194 loc) · 5.39 KB
/
Copy pathcore-config.unit.test.ts
File metadata and controls
201 lines (194 loc) · 5.39 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { describe, expect, it } from 'vitest';
import { type CoreConfig, coreConfigSchema } from './core-config.js';
describe('coreConfigSchema', () => {
it('should accept a valid core configuration with all entities', () => {
expect(() =>
coreConfigSchema.parse({
categories: [
{
slug: 'test-results',
title: 'Test results',
refs: [
{
plugin: 'jest',
slug: 'unit-tests',
type: 'group',
weight: 1,
},
],
},
],
plugins: [
{
slug: 'jest',
title: 'Jest',
icon: 'jest',
runner: { command: 'npm run test', outputFile: 'jest-output.json' },
audits: [{ slug: 'jest-unit-tests', title: 'Jest unit tests.' }],
groups: [
{
slug: 'unit-tests',
title: 'Unit tests',
refs: [{ slug: 'jest-unit-tests', weight: 2 }],
},
],
},
],
persist: { format: ['md'] },
upload: {
apiKey: 'AP7-K3Y',
organization: 'code-pushup',
project: 'cli',
server: 'https://api.code-pushup.org',
},
} satisfies CoreConfig),
).not.toThrow();
});
it('should accept a minimal core configuration', () => {
expect(() =>
coreConfigSchema.parse({
plugins: [
{
slug: 'eslint',
title: 'ESLint',
icon: 'eslint',
runner: { command: 'npm run lint', outputFile: 'output.json' },
audits: [{ slug: 'no-magic-numbers', title: 'No magic numbers.' }],
},
],
} satisfies CoreConfig),
).not.toThrow();
});
it('should throw for an empty configuration with no plugins', () => {
expect(() => coreConfigSchema.parse({ plugins: [] })).toThrow('too_small');
});
it('should throw for a category reference not found in audits', () => {
expect(() =>
coreConfigSchema.parse({
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
refs: [
{
plugin: 'vitest',
slug: 'unit-tests',
type: 'audit',
weight: 1,
},
],
},
],
plugins: [
{
slug: 'jest',
title: 'Jest',
icon: 'jest',
runner: { command: 'npm run test', outputFile: 'output.json' },
audits: [{ slug: 'unit-tests', title: 'Jest unit tests.' }],
},
],
} satisfies CoreConfig),
).toThrow(
String.raw`Category references audits or groups which don't exist: audit \"unit-tests\" (plugin \"vitest\")`,
);
});
it('should throw for a category reference not found in groups', () => {
expect(() =>
coreConfigSchema.parse({
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
refs: [
{
plugin: 'eslint',
slug: 'eslint-errors',
type: 'group',
weight: 1,
},
],
},
],
plugins: [
{
slug: 'eslint',
title: 'ESLint',
icon: 'eslint',
runner: { command: 'npm run lint', outputFile: 'output.json' },
audits: [{ slug: 'eslint-errors', title: 'ESLint errors.' }],
groups: [
{
slug: 'eslint-suggestions',
title: 'ESLint suggestions',
refs: [{ slug: 'eslint-errors', weight: 1 }],
},
],
},
],
} satisfies CoreConfig),
).toThrow(
String.raw`Category references audits or groups which don't exist: group \"eslint-errors\" (plugin \"eslint\")`,
);
});
it('should throw for a category with a zero-weight audit', () => {
const config = {
categories: [
{
slug: 'performance',
title: 'Performance',
refs: [
{
slug: 'performance',
weight: 1,
type: 'group',
plugin: 'lighthouse',
},
],
},
{
slug: 'best-practices',
title: 'Best practices',
refs: [
{
slug: 'best-practices',
weight: 1,
type: 'group',
plugin: 'lighthouse',
},
],
},
],
plugins: [
{
slug: 'lighthouse',
title: 'Lighthouse',
icon: 'lighthouse',
runner: async () => [
{
slug: 'csp-xss',
score: 1,
value: 1,
},
],
audits: [
{
slug: 'csp-xss',
title: 'Ensure CSP is effective against XSS attacks',
},
],
groups: [
{
slug: 'best-practices',
title: 'Best practices',
refs: [{ slug: 'csp-xss', weight: 0 }],
},
],
},
],
} satisfies CoreConfig;
expect(() => coreConfigSchema.parse(config)).toThrow(
'A category must have at least 1 ref with weight > 0.',
);
});
});