-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathaxe-plugin.ts
More file actions
56 lines (51 loc) · 1.63 KB
/
axe-plugin.ts
File metadata and controls
56 lines (51 loc) · 1.63 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
import { createRequire } from 'node:module';
import {
type PluginConfig,
type PluginUrls,
validate,
} from '@code-pushup/models';
import { normalizeUrlInput } from '@code-pushup/utils';
import { type AxePluginOptions, axePluginOptionsSchema } from './config.js';
import { AXE_PLUGIN_SLUG, AXE_PLUGIN_TITLE } from './constants.js';
import { processAuditsAndGroups } from './meta/processing.js';
import { createRunnerFunction } from './runner/runner.js';
/**
* Code PushUp plugin for accessibility testing using axe-core.
*
* @public
* @param urls - {@link PluginUrls} URL(s) to test
* @param options - {@link AxePluginOptions} Plugin options
* @returns Plugin configuration
*/
export function axePlugin(
urls: PluginUrls,
options: AxePluginOptions = {},
): PluginConfig {
const { preset, scoreTargets, timeout } = validate(
axePluginOptionsSchema,
options,
);
const { urls: normalizedUrls, context } = normalizeUrlInput(urls);
const { audits, groups, ruleIds } = processAuditsAndGroups(
normalizedUrls,
preset,
);
const packageJson = createRequire(import.meta.url)(
'../../package.json',
) as typeof import('../../package.json');
return {
slug: AXE_PLUGIN_SLUG,
title: AXE_PLUGIN_TITLE,
icon: 'folder-syntax',
description:
'Official Code PushUp Axe plugin for automated accessibility testing',
docsUrl: 'https://www.npmjs.com/package/@code-pushup/axe-plugin',
packageName: packageJson.name,
version: packageJson.version,
audits,
groups,
runner: createRunnerFunction(normalizedUrls, ruleIds, timeout),
context,
...(scoreTargets && { scoreTargets }),
};
}