Skip to content

Commit f0793e7

Browse files
committed
docs(plugin-axe): improve documentation coverage
1 parent 0d9fffb commit f0793e7

File tree

10 files changed

+30
-0
lines changed

10 files changed

+30
-0
lines changed

packages/plugin-axe/src/lib/categories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function expandCategories(
5858
);
5959
}
6060

61+
/** Creates an aggregated accessibility category from Axe groups. */
6162
export function createAggregatedCategory(
6263
groups: Group[],
6364
context: PluginUrlContext,
@@ -72,6 +73,7 @@ export function createAggregatedCategory(
7273
};
7374
}
7475

76+
/** Expands category refs for multiple URLs. */
7577
export function expandAggregatedCategory(
7678
category: CategoryConfig,
7779
context: PluginUrlContext,
@@ -84,6 +86,7 @@ export function expandAggregatedCategory(
8486
};
8587
}
8688

89+
/** Extracts unique group slugs from Axe groups. */
8790
export function extractGroupSlugs(groups: Group[]): AxeCategoryGroupSlug[] {
8891
const slugs = groups.map(({ slug }) => removeIndex(slug));
8992
return [...new Set(slugs)].filter(isAxeGroupSlug);

packages/plugin-axe/src/lib/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import type { AxePreset } from './config.js';
22

3+
/** Unique identifier for the Axe plugin. */
34
export const AXE_PLUGIN_SLUG = 'axe';
5+
6+
/** Display title for the Axe plugin. */
47
export const AXE_PLUGIN_TITLE = 'Axe';
58

9+
/** Default WCAG preset used when none is specified. */
610
export const AXE_DEFAULT_PRESET = 'wcag21aa';
711

12+
/** Default timeout in milliseconds for page operations. */
813
export const DEFAULT_TIMEOUT_MS = 30_000;
914

15+
/** Human-readable names for each Axe preset. */
1016
export const AXE_PRESET_NAMES: Record<AxePreset, string> = {
1117
wcag21aa: 'WCAG 2.1 AA',
1218
wcag22aa: 'WCAG 2.2 AA',

packages/plugin-axe/src/lib/groups.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const WCAG_PRESET_TAGS: Record<AxeWcagPreset, AxeWcagTag[]> = {
2727
wcag22aa: ['wcag2a', 'wcag21a', 'wcag2aa', 'wcag21aa', 'wcag22aa'],
2828
};
2929

30+
/** Returns the WCAG tags for a given preset. */
3031
export function getWcagPresetTags(preset: AxeWcagPreset): AxeWcagTag[] {
3132
return WCAG_PRESET_TAGS[preset];
3233
}
@@ -54,6 +55,7 @@ export const axeCategoryGroupSlugSchema = z
5455

5556
export type AxeCategoryGroupSlug = z.infer<typeof axeCategoryGroupSlugSchema>;
5657

58+
/** Maps category group slugs to human-readable titles. */
5759
export const CATEGORY_GROUPS: Record<AxeCategoryGroupSlug, string> = {
5860
aria: 'ARIA',
5961
color: 'Color & Contrast',
@@ -70,6 +72,7 @@ export const CATEGORY_GROUPS: Record<AxeCategoryGroupSlug, string> = {
7072
'time-and-media': 'Media',
7173
};
7274

75+
/** Type guard for valid Axe group slugs. */
7376
export function isAxeGroupSlug(slug: unknown): slug is AxeCategoryGroupSlug {
7477
return axeCategoryGroupSlugSchema.safeParse(slug).success;
7578
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { pluginMetaLogFormatter } from '@code-pushup/utils';
22
import { AXE_PLUGIN_TITLE } from '../constants.js';
33

4+
/** Formats log messages with the Axe plugin prefix. */
45
export const formatMetaLog = pluginMetaLogFormatter(AXE_PLUGIN_TITLE);

packages/plugin-axe/src/lib/meta/processing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
transformRulesToGroups,
1717
} from './transform.js';
1818

19+
/** Loads and processes Axe rules into audits and groups, expanding for multiple URLs if needed. */
1920
export function processAuditsAndGroups(
2021
urls: string[],
2122
preset: AxePreset,

packages/plugin-axe/src/lib/meta/transform.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import {
88
getWcagPresetTags,
99
} from '../groups.js';
1010

11+
/** Loads Axe rules filtered by the specified preset. */
1112
export function loadAxeRules(preset: AxePreset): axe.RuleMetadata[] {
1213
const tags = getPresetTags(preset);
1314
return tags.length === 0 ? axe.getRules() : axe.getRules(tags);
1415
}
1516

17+
/** Transforms Axe rule metadata into Code PushUp audit definitions. */
1618
export function transformRulesToAudits(rules: axe.RuleMetadata[]): Audit[] {
1719
return rules.map(rule => ({
1820
slug: rule.ruleId,
@@ -22,6 +24,7 @@ export function transformRulesToAudits(rules: axe.RuleMetadata[]): Audit[] {
2224
}));
2325
}
2426

27+
/** Transforms Axe rules into Code PushUp groups based on accessibility categories. */
2528
export function transformRulesToGroups(rules: axe.RuleMetadata[]): Group[] {
2629
const groups = createCategoryGroups(rules);
2730
return groups.filter(({ refs }) => refs.length > 0);

packages/plugin-axe/src/lib/runner/run-axe.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ export type AxeUrlResult = {
3434
auditOutputs: AuditOutputs;
3535
};
3636

37+
/**
38+
* Manages Playwright browser lifecycle and runs Axe accessibility audits.
39+
* Handles browser installation, authentication state, and URL analysis.
40+
*/
3741
export class AxeRunner {
3842
private browser: Browser | undefined;
3943
private browserInstalled = false;
4044
private storageState: BrowserContextOptions['storageState'];
4145

46+
/** Analyzes a URL for accessibility issues using Axe. */
4247
async analyzeUrl(args: AxeUrlArgs): Promise<AxeUrlResult> {
4348
const browser = await this.launchBrowser();
4449
const { url, urlIndex, urlsCount } = args;
@@ -67,6 +72,7 @@ export class AxeRunner {
6772
});
6873
}
6974

75+
/** Runs setup script and captures authentication state for reuse. */
7076
async captureAuthState(
7177
setupFn: SetupFunction,
7278
timeout: number,
@@ -87,6 +93,7 @@ export class AxeRunner {
8793
}
8894
}
8995

96+
/** Closes the browser and clears authentication state. */
9097
async close(): Promise<void> {
9198
this.storageState = undefined;
9299
this.browserInstalled = false;
@@ -127,6 +134,7 @@ export class AxeRunner {
127134
this.browserInstalled = true;
128135
}
129136

137+
/** Lazily launches or returns existing Chromium browser instance. */
130138
private async launchBrowser(): Promise<Browser> {
131139
if (this.browser) {
132140
return this.browser;

packages/plugin-axe/src/lib/runner/runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { AxeRunner, type AxeUrlArgs, type AxeUrlResult } from './run-axe.js';
1212
import { loadSetupScript } from './setup.js';
1313

14+
/** Creates a runner function that executes Axe accessibility audits for given URLs. */
1415
export function createRunnerFunction(
1516
urls: string[],
1617
ruleIds: string[],

packages/plugin-axe/src/lib/runner/setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const setupScriptModuleSchema = z
2626
'ES module with a default export containing the authentication setup function',
2727
});
2828

29+
/** Loads and validates a setup script module from the given path. */
2930
export async function loadSetupScript(
3031
setupScript: string,
3132
): Promise<SetupFunction> {
@@ -47,6 +48,7 @@ export async function loadSetupScript(
4748
return validModule.default;
4849
}
4950

51+
/** Executes the setup function with the provided Playwright page. */
5052
export async function runSetup(
5153
setupFn: SetupFunction,
5254
page: Page,

packages/plugin-axe/src/lib/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CategoryRef } from '@code-pushup/models';
22
import { AXE_PLUGIN_SLUG } from './constants.js';
33
import type { AxeGroupSlug } from './groups.js';
44

5+
/** Creates a category ref to an Axe group. */
56
export function axeGroupRef(groupSlug: AxeGroupSlug, weight = 1): CategoryRef {
67
return {
78
plugin: AXE_PLUGIN_SLUG,
@@ -11,6 +12,7 @@ export function axeGroupRef(groupSlug: AxeGroupSlug, weight = 1): CategoryRef {
1112
};
1213
}
1314

15+
/** Creates a category ref to an Axe audit. */
1416
export function axeAuditRef(auditSlug: string, weight = 1): CategoryRef {
1517
return {
1618
plugin: AXE_PLUGIN_SLUG,

0 commit comments

Comments
 (0)