Skip to content

Commit 5ebadbb

Browse files
committed
test(models): validate error for zero-weight refs in core config
1 parent 9b8c960 commit 5ebadbb

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/models/src/lib/core-config.unit.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,60 @@ describe('coreConfigSchema', () => {
136136
'category references need to point to an audit or group: eslint#eslint-errors (group)',
137137
);
138138
});
139+
140+
it('should throw for a category with a zero-weight audit', () => {
141+
const config = {
142+
categories: [
143+
{
144+
slug: 'performance',
145+
title: 'Performance',
146+
refs: [
147+
{
148+
slug: 'performance',
149+
weight: 1,
150+
type: 'group',
151+
plugin: 'lighthouse',
152+
},
153+
],
154+
},
155+
{
156+
slug: 'best-practices',
157+
title: 'Best practices',
158+
refs: [
159+
{
160+
slug: 'best-practices',
161+
weight: 1,
162+
type: 'group',
163+
plugin: 'lighthouse',
164+
},
165+
],
166+
},
167+
],
168+
plugins: [
169+
{
170+
slug: 'lighthouse',
171+
title: 'Lighthouse',
172+
icon: 'lighthouse',
173+
runner: { command: 'npm run lint', outputFile: 'output.json' },
174+
audits: [
175+
{
176+
slug: 'csp-xss',
177+
title: 'Ensure CSP is effective against XSS attacks',
178+
},
179+
],
180+
groups: [
181+
{
182+
slug: 'best-practices',
183+
title: 'Best practices',
184+
refs: [{ slug: 'csp-xss', weight: 0 }],
185+
},
186+
],
187+
},
188+
],
189+
} satisfies CoreConfig;
190+
191+
expect(() => coreConfigSchema.parse(config)).toThrow(
192+
'In a category, there has to be at least one ref with weight > 0. Affected refs: csp-xss',
193+
);
194+
});
139195
});

0 commit comments

Comments
 (0)