Skip to content

Commit f15817b

Browse files
committed
feat(plugin-axe): add plugin configuration validation
1 parent 44bc1af commit f15817b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { z } from 'zod';
2+
import { pluginScoreTargetsSchema } from '@code-pushup/models';
3+
import { AXE_DEFAULT_PRESET, AXE_PRESETS } from './constants';
4+
5+
export const axePluginOptionsSchema = z
6+
.object({
7+
preset: z.enum(AXE_PRESETS).default(AXE_DEFAULT_PRESET).meta({
8+
description:
9+
'Accessibility ruleset preset (default: wcag21aa for WCAG 2.1 Level AA compliance)',
10+
}),
11+
scoreTargets: pluginScoreTargetsSchema.optional(),
12+
})
13+
.meta({
14+
title: 'AxePluginOptions',
15+
description: 'Configuration options for the Axe plugin',
16+
});
17+
18+
export type AxePluginOptions = z.input<typeof axePluginOptionsSchema>;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { axePluginOptionsSchema } from './config.js';
3+
4+
describe('axePluginOptionsSchema', () => {
5+
it('should accept empty options object with default preset', () => {
6+
expect(axePluginOptionsSchema.parse({}).preset).toBe('wcag21aa');
7+
});
8+
9+
it('should accept wcag21aa preset', () => {
10+
expect(() =>
11+
axePluginOptionsSchema.parse({ preset: 'wcag21aa' }),
12+
).not.toThrow();
13+
});
14+
15+
it('should accept wcag22aa preset', () => {
16+
expect(() =>
17+
axePluginOptionsSchema.parse({ preset: 'wcag22aa' }),
18+
).not.toThrow();
19+
});
20+
21+
it('should accept best-practice preset', () => {
22+
expect(() =>
23+
axePluginOptionsSchema.parse({ preset: 'best-practice' }),
24+
).not.toThrow();
25+
});
26+
27+
it('should accept all preset', () => {
28+
expect(() => axePluginOptionsSchema.parse({ preset: 'all' })).not.toThrow();
29+
});
30+
31+
it('should accept number scoreTargets', () => {
32+
expect(() =>
33+
axePluginOptionsSchema.parse({ scoreTargets: 0.99 }),
34+
).not.toThrow();
35+
});
36+
37+
it('should accept object scoreTargets', () => {
38+
expect(() =>
39+
axePluginOptionsSchema.parse({
40+
scoreTargets: { 'color-contrast': 0.99 },
41+
}),
42+
).not.toThrow();
43+
});
44+
45+
it('should throw for invalid preset', () => {
46+
expect(() => axePluginOptionsSchema.parse({ preset: 'wcag3aa' })).toThrow();
47+
});
48+
49+
it('should throw for invalid scoreTargets value', () => {
50+
expect(() => axePluginOptionsSchema.parse({ scoreTargets: 1.5 })).toThrow();
51+
});
52+
53+
it('should throw for negative scoreTargets', () => {
54+
expect(() =>
55+
axePluginOptionsSchema.parse({ scoreTargets: -0.1 }),
56+
).toThrow();
57+
});
58+
});

0 commit comments

Comments
 (0)