Skip to content

Commit d9d0a6e

Browse files
committed
feat(plugin-axe): add audits and groups processing
1 parent 4ba86c7 commit d9d0a6e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Audit, Group } from '@code-pushup/models';
2+
import {
3+
expandAuditsForUrls,
4+
expandGroupsForUrls,
5+
shouldExpandForUrls,
6+
} from '@code-pushup/utils';
7+
import type { AxePreset } from './constants';
8+
import {
9+
loadAxeRules,
10+
transformRulesToAudits,
11+
transformRulesToGroups,
12+
} from './meta/transform';
13+
14+
export function processAuditsAndGroups(
15+
urls: string[],
16+
preset: AxePreset,
17+
): {
18+
audits: Audit[];
19+
groups: Group[];
20+
ruleIds: string[];
21+
} {
22+
const rules = loadAxeRules(preset);
23+
const ruleIds = rules.map(({ ruleId }) => ruleId);
24+
const audits = transformRulesToAudits(rules);
25+
const groups = transformRulesToGroups(rules, preset);
26+
27+
if (!shouldExpandForUrls(urls.length)) {
28+
return { audits, groups, ruleIds };
29+
}
30+
31+
return {
32+
audits: expandAuditsForUrls(audits, urls),
33+
groups: expandGroupsForUrls(groups, urls),
34+
ruleIds,
35+
};
36+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { processAuditsAndGroups } from './processing';
3+
4+
describe('processAuditsAndGroups', () => {
5+
it('should return audits and groups without expansion for single URL', () => {
6+
const { audits, groups } = processAuditsAndGroups(
7+
['https://example.com'],
8+
'wcag21aa',
9+
);
10+
11+
expect(audits.length).toBeGreaterThan(0);
12+
expect(groups.length).toBeGreaterThan(0);
13+
14+
expect(audits[0]?.slug).not.toContain('-1');
15+
expect(groups[0]?.slug).not.toContain('-1');
16+
});
17+
18+
it('should expand audits and groups for multiple URLs', () => {
19+
const { audits, groups } = processAuditsAndGroups(
20+
['https://example.com', 'https://another-example.com'],
21+
'wcag21aa',
22+
);
23+
24+
expect(audits.length).toBeGreaterThan(0);
25+
expect(groups.length).toBeGreaterThan(0);
26+
27+
expect(audits[0]?.slug).toContain('-1');
28+
expect(groups[0]?.slug).toContain('-1');
29+
30+
expect(audits[0]?.title).toContain('(example.com)');
31+
expect(groups[0]?.title).toContain('(example.com)');
32+
});
33+
});

0 commit comments

Comments
 (0)