Skip to content

Commit 5f02048

Browse files
Merge pull request #246 from abhinaba-ghosh/docs/axe-playwright-types
docs(types): add full type definitions and JSDoc for axe-playwright m…
2 parents 0be5f49 + 07a09be commit 5f02048

File tree

2 files changed

+128
-2
lines changed

2 files changed

+128
-2
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { Page } from 'playwright';
2+
import {
3+
AxeResults,
4+
ElementContext,
5+
Result,
6+
RunOptions,
7+
Spec,
8+
ImpactValue,
9+
Locale,
10+
Rule,
11+
Check
12+
} from 'axe-core';
13+
14+
export interface NodeViolation {
15+
target: string;
16+
html: string;
17+
violations: string;
18+
}
19+
20+
export interface Aggregate {
21+
[key: string]: {
22+
target: string;
23+
html: string;
24+
violations: number[];
25+
};
26+
}
27+
28+
export interface Reporter {
29+
report(violations: Result[]): Promise<void>;
30+
}
31+
32+
export interface axeOptionsConfig {
33+
axeOptions?: RunOptions;
34+
}
35+
36+
export interface ConfigOptions {
37+
branding?: {
38+
brand?: string;
39+
application?: string;
40+
};
41+
reporter?: 'v1' | 'v2' | 'no-passes';
42+
checks?: Check[];
43+
rules?: Rule[];
44+
locale?: Locale;
45+
axeVersion?: string;
46+
}
47+
48+
export type AxeOptions = {
49+
includedImpacts?: ImpactValue[];
50+
detailedReport?: boolean;
51+
detailedReportOptions?: { html?: boolean };
52+
verbose?: boolean;
53+
} & axeOptionsConfig;
54+
55+
/**
56+
* Injects axe executable commands in the active window
57+
* @param page Playwright Page object
58+
*/
59+
export function injectAxe(page: Page): Promise<void>;
60+
/**
61+
* Configures axe runtime options
62+
* @param page Playwright Page object
63+
* @param configurationOptions Axe configuration options
64+
*/
65+
export function configureAxe(page: Page, configurationOptions?: ConfigOptions): Promise<void>;
66+
/**
67+
* Runs axe-core tools on the relevant page and returns all results
68+
* @param page Playwright Page object
69+
* @param context Optional element context
70+
* @param options Optional axe run options
71+
*/
72+
export function getAxeResults(page: Page, context?: ElementContext, options?: RunOptions): Promise<AxeResults>;
73+
/**
74+
* Runs axe-core tools and returns all accessibility violations detected on the page
75+
* @param page Playwright Page object
76+
* @param context Optional element context
77+
* @param options Optional axe run options
78+
*/
79+
export function getViolations(page: Page, context?: ElementContext, options?: RunOptions): Promise<Result[]>;
80+
/**
81+
* Report violations using the provided reporter
82+
* @param violations Array of axe-core Result objects
83+
* @param reporter Reporter instance
84+
*/
85+
export function reportViolations(violations: Result[], reporter: Reporter): Promise<void>;
86+
/**
87+
* Performs Axe validations and reporting
88+
* @param page Playwright Page object
89+
* @param context Optional element context
90+
* @param axeOptions Axe options
91+
* @param skipFailures Whether to skip failures
92+
* @param reporter Reporter instance or type
93+
* @param options Additional options
94+
*/
95+
export function checkA11y(
96+
page: Page,
97+
context?: ElementContext,
98+
axeOptions?: AxeOptions,
99+
skipFailures?: boolean,
100+
reporter?: Reporter | 'default' | 'html' | 'junit' | 'v2',
101+
options?: any
102+
): Promise<void>;
103+
/**
104+
* Filters violations by impact values
105+
* @param violations Array of axe-core Result objects
106+
* @param includedImpacts Array of impact values to include
107+
*/
108+
export function getImpactedViolations(
109+
violations: Result[],
110+
includedImpacts?: ImpactValue[]
111+
): Result[];
112+
/**
113+
* Asserts or warns based on the presence of violations and skipFailures flag
114+
* @param violations Array of axe-core Result objects
115+
* @param skipFailures Whether to skip failures
116+
*/
117+
export function testResultDependsOnViolations(
118+
violations: Result[],
119+
skipFailures: boolean
120+
): void;
121+
/**
122+
* Aggregates and describes violations for reporting
123+
* @param violations Array of axe-core Result objects
124+
* @returns Array of NodeViolation objects
125+
*/
126+
export function describeViolations(violations: Result[]): NodeViolation[];

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"declaration": true,
77
"rootDir": "src",
88
"moduleResolution": "node",
9-
"typeRoots": ["node_modules/@types"],
9+
"typeRoots": ["node_modules/@types", "src/types"],
1010
"esModuleInterop": true,
1111
"outDir": "dist",
1212
"noImplicitAny": false,
13-
"types": ["node", "jest"]
13+
"types": ["node", "jest", "axe-playwright"]
1414
},
1515
"exclude": ["node_modules"],
1616
"include": ["src/"]

0 commit comments

Comments
 (0)