Skip to content

Commit

Permalink
test(models): validate error for zero-weight refs in core config
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-skryl committed Jan 7, 2025
1 parent 75cd470 commit 8610bf6
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions packages/models/src/lib/core-config.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,60 @@ describe('coreConfigSchema', () => {
'category references need to point to an audit or group: eslint#eslint-errors (group)',
);
});

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: { command: 'npm run lint', outputFile: 'output.json' },
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(
'In a category, there has to be at least one ref with weight > 0. Affected refs: csp-xss',
);
});
});

0 comments on commit 8610bf6

Please sign in to comment.