axe-playwright 1.1.8 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +12 -0
- package/README.md +9 -15
- package/dist/index.js +16 -6
- package/index.d.ts +18 -2
- package/package.json +5 -5
- package/src/index.ts +22 -8
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://app.circleci.com/pipelines/github/abhinaba-ghosh/axe-playwright)
|
|
6
6
|
[](https://www.npmjs.com/package/axe-playwright)
|
|
7
|
+
[](https://www.npmjs.com/package/axe-playwright)
|
|
7
8
|
|
|
8
9
|
[Axe](https://www.deque.com/axe/) is an accessibility testing engine for websites and other HTML-based user interfaces. This package provides simple axe analyser commands which you can incorporate in your [Playwright](https://www.npmjs.com/package/playwright) tests.The idea is highly inspired by [Andy Van Slaars](https://github.com/avanslaars) cypress-axe project.
|
|
9
10
|
|
|
@@ -123,11 +124,11 @@ A class instance that implements the `Reporter` interface. Custom reporter insta
|
|
|
123
124
|
|
|
124
125
|
Disables assertions based on violations and only logs violations to the console output. If you set `skipFailures` as `true`, although accessibility check is not passed, your test will not fail. It will simply print the violations in the console, but will not make the test fail.
|
|
125
126
|
|
|
126
|
-
###
|
|
127
|
+
### getAxeResults
|
|
127
128
|
|
|
128
|
-
This will run axe against the document at the point in which it is called, then
|
|
129
|
+
This will run axe against the document at the point in which it is called, then returns the full set of results as reported by `axe.run`.
|
|
129
130
|
|
|
130
|
-
#### Parameters on
|
|
131
|
+
#### Parameters on getAxeResults
|
|
131
132
|
|
|
132
133
|
##### page (mandatory)
|
|
133
134
|
|
|
@@ -141,22 +142,15 @@ Defines the scope of the analysis - the part of the DOM that you would like to a
|
|
|
141
142
|
|
|
142
143
|
Set of options passed into rules or checks, temporarily modifying them. This contrasts with axe.configure, which is more permanent.
|
|
143
144
|
|
|
144
|
-
The
|
|
145
|
-
|
|
146
|
-
The `includedImpacts` key is an array of strings that map to `impact` levels in violations. Specifying this array will only include violations where the impact matches one of the included values. Possible impact values are "minor", "moderate", "serious", or "critical".
|
|
145
|
+
The object is of the same type which is [accepted by `axe.run`'s options argument](https://www.deque.com/axe/documentation/api-documentation/#parameters-axerun) and directly forwarded to it.
|
|
147
146
|
|
|
148
|
-
|
|
149
|
-
e-effects, such as adding custom output to the terminal.
|
|
147
|
+
### getViolations
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
This will run axe against the document at the point in which it is called, then return you an array of accessibility violations (i.e. the `violations` array included in the `getAxeResults` result).
|
|
152
150
|
|
|
153
|
-
|
|
151
|
+
#### Parameters on getViolations (axe.run)
|
|
154
152
|
|
|
155
|
-
|
|
156
|
-
{
|
|
157
|
-
html?: boolean // include the full html for the offending nodes
|
|
158
|
-
}
|
|
159
|
-
```
|
|
153
|
+
Identical to [parameters of getAxeResults](#parameters-on-getAxeResults).
|
|
160
154
|
|
|
161
155
|
### reportViolations
|
|
162
156
|
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
31
31
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
32
|
};
|
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.checkA11y = exports.reportViolations = exports.getViolations = exports.configureAxe = exports.injectAxe = void 0;
|
|
34
|
+
exports.checkA11y = exports.reportViolations = exports.getViolations = exports.getAxeResults = exports.configureAxe = exports.injectAxe = void 0;
|
|
35
35
|
const fs = __importStar(require("fs"));
|
|
36
36
|
const utils_1 = require("./utils");
|
|
37
37
|
const defaultTerminalReporter_1 = __importDefault(require("./reporter/defaultTerminalReporter"));
|
|
@@ -54,16 +54,26 @@ const configureAxe = (page, configurationOptions = {}) => __awaiter(void 0, void
|
|
|
54
54
|
});
|
|
55
55
|
exports.configureAxe = configureAxe;
|
|
56
56
|
/**
|
|
57
|
-
* Runs axe-core tools on the relevant page and returns all
|
|
57
|
+
* Runs axe-core tools on the relevant page and returns all results
|
|
58
58
|
* @param page
|
|
59
59
|
* @param context
|
|
60
60
|
* @param options
|
|
61
61
|
*/
|
|
62
|
-
const
|
|
62
|
+
const getAxeResults = (page, context, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
63
|
const result = yield page.evaluate(([context, options]) => {
|
|
64
|
-
|
|
65
|
-
return window.axe.run(context || window.document, axeOptions);
|
|
64
|
+
return window.axe.run(context || window.document, options);
|
|
66
65
|
}, [context, options]);
|
|
66
|
+
return result;
|
|
67
|
+
});
|
|
68
|
+
exports.getAxeResults = getAxeResults;
|
|
69
|
+
/**
|
|
70
|
+
* Runs axe-core tools on the relevant page and returns all accessibility violations detected on the page
|
|
71
|
+
* @param page
|
|
72
|
+
* @param context
|
|
73
|
+
* @param options
|
|
74
|
+
*/
|
|
75
|
+
const getViolations = (page, context, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const result = yield exports.getAxeResults(page, context, options);
|
|
67
77
|
return result.violations;
|
|
68
78
|
});
|
|
69
79
|
exports.getViolations = getViolations;
|
|
@@ -90,7 +100,7 @@ const checkA11y = (page, context, options, skipFailures, reporter) => __awaiter(
|
|
|
90
100
|
if (options === void 0) { options = undefined; }
|
|
91
101
|
if (skipFailures === void 0) { skipFailures = false; }
|
|
92
102
|
if (reporter === void 0) { reporter = new defaultTerminalReporter_1.default(options === null || options === void 0 ? void 0 : options.detailedReport, (_a = options === null || options === void 0 ? void 0 : options.detailedReportOptions) === null || _a === void 0 ? void 0 : _a.html); }
|
|
93
|
-
const violations = yield exports.getViolations(page, context, options);
|
|
103
|
+
const violations = yield exports.getViolations(page, context, options === null || options === void 0 ? void 0 : options.axeOptions);
|
|
94
104
|
const impactedViolations = utils_1.getImpactedViolations(violations, options === null || options === void 0 ? void 0 : options.includedImpacts);
|
|
95
105
|
yield exports.reportViolations(impactedViolations, reporter);
|
|
96
106
|
utils_1.testResultDependsOnViolations(impactedViolations, skipFailures);
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Check, ElementContext, ImpactValue, Locale, Result, Rule, RunOptions } from 'axe-core'
|
|
1
|
+
import { AxeResults, Check, ElementContext, ImpactValue, Locale, Result, Rule, RunOptions } from 'axe-core'
|
|
2
2
|
import { Page } from 'playwright'
|
|
3
3
|
|
|
4
4
|
export interface axeOptionsConfig {
|
|
@@ -25,6 +25,14 @@ export default interface Reporter {
|
|
|
25
25
|
report(violations: Result[]): Promise<void>
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Default implementation of a reporter which prints a summary to the console.
|
|
30
|
+
*/
|
|
31
|
+
export class DefaultTerminalReporter implements Reporter {
|
|
32
|
+
constructor(detailedReport: boolean | undefined, includeHtml: boolean | undefined)
|
|
33
|
+
report(violations: Result[]): Promise<void>
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
export type Options = {
|
|
29
37
|
includedImpacts?: ImpactValue[]
|
|
30
38
|
detailedReport?: boolean
|
|
@@ -61,13 +69,21 @@ export function checkA11y(
|
|
|
61
69
|
*/
|
|
62
70
|
export function configureAxe(page: Page, options?: ConfigOptions): Promise<void>
|
|
63
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Runs axe-core tools on the relevant page and returns all results
|
|
74
|
+
* @param page
|
|
75
|
+
* @param context
|
|
76
|
+
* @param options
|
|
77
|
+
*/
|
|
78
|
+
export function getAxeResults(page: Page, context?: ElementContext, options?: RunOptions): Promise<AxeResults>
|
|
79
|
+
|
|
64
80
|
/**
|
|
65
81
|
* Runs axe-core tools on the relevant page and returns all accessibility violations detected on the page
|
|
66
82
|
* @param page
|
|
67
83
|
* @param context
|
|
68
84
|
* @param options
|
|
69
85
|
*/
|
|
70
|
-
export function getViolations(page: Page, context?: ElementContext, options?:
|
|
86
|
+
export function getViolations(page: Page, context?: ElementContext, options?: RunOptions): Promise<Result[]>
|
|
71
87
|
|
|
72
88
|
/**
|
|
73
89
|
* Report violations given the reporter.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-playwright",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Custom Playwright commands to inject axe-core and test for a11y",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"author": "Abhinaba Ghosh",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/is-ci": "^
|
|
29
|
-
"@types/jest": "^
|
|
30
|
-
"@types/node": "^
|
|
28
|
+
"@types/is-ci": "^3.0.0",
|
|
29
|
+
"@types/jest": "^27.0.3",
|
|
30
|
+
"@types/node": "^17.0.4",
|
|
31
31
|
"jest": "^26.6.3",
|
|
32
|
-
"jest-each": "^
|
|
32
|
+
"jest-each": "^27.0.2",
|
|
33
33
|
"jest-playwright-preset": "^1.3.1",
|
|
34
34
|
"playwright": "^1.1.1",
|
|
35
35
|
"prettier": "^2.0.5",
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Page } from 'playwright'
|
|
2
2
|
import * as fs from 'fs'
|
|
3
|
-
import { ElementContext, Result, RunOptions, Spec } from 'axe-core'
|
|
3
|
+
import { AxeResults, ElementContext, Result, RunOptions, Spec } from 'axe-core'
|
|
4
4
|
import { ConfigOptions, Options } from '../index'
|
|
5
5
|
import { getImpactedViolations, testResultDependsOnViolations } from './utils'
|
|
6
6
|
import DefaultTerminalReporter from './reporter/defaultTerminalReporter'
|
|
@@ -40,24 +40,38 @@ export const configureAxe = async (
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Runs axe-core tools on the relevant page and returns all
|
|
43
|
+
* Runs axe-core tools on the relevant page and returns all results
|
|
44
44
|
* @param page
|
|
45
45
|
* @param context
|
|
46
46
|
* @param options
|
|
47
47
|
*/
|
|
48
|
-
export const
|
|
48
|
+
export const getAxeResults = async (
|
|
49
49
|
page: Page,
|
|
50
50
|
context?: ElementContext,
|
|
51
|
-
options?:
|
|
52
|
-
): Promise<
|
|
51
|
+
options?: RunOptions,
|
|
52
|
+
): Promise<AxeResults> => {
|
|
53
53
|
const result = await page.evaluate(
|
|
54
54
|
([context, options]) => {
|
|
55
|
-
|
|
56
|
-
return window.axe.run(context || window.document, axeOptions)
|
|
55
|
+
return window.axe.run(context || window.document, options)
|
|
57
56
|
},
|
|
58
57
|
[context, options],
|
|
59
58
|
)
|
|
60
59
|
|
|
60
|
+
return result
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Runs axe-core tools on the relevant page and returns all accessibility violations detected on the page
|
|
65
|
+
* @param page
|
|
66
|
+
* @param context
|
|
67
|
+
* @param options
|
|
68
|
+
*/
|
|
69
|
+
export const getViolations = async (
|
|
70
|
+
page: Page,
|
|
71
|
+
context?: ElementContext,
|
|
72
|
+
options?: RunOptions,
|
|
73
|
+
): Promise<Result[]> => {
|
|
74
|
+
const result = await getAxeResults(page, context, options)
|
|
61
75
|
return result.violations
|
|
62
76
|
}
|
|
63
77
|
|
|
@@ -85,7 +99,7 @@ export const checkA11y = async (
|
|
|
85
99
|
skipFailures: boolean = false,
|
|
86
100
|
reporter: Reporter = new DefaultTerminalReporter(options?.detailedReport, options?.detailedReportOptions?.html),
|
|
87
101
|
): Promise<void> => {
|
|
88
|
-
const violations = await getViolations(page, context, options)
|
|
102
|
+
const violations = await getViolations(page, context, options?.axeOptions)
|
|
89
103
|
|
|
90
104
|
const impactedViolations = getImpactedViolations(
|
|
91
105
|
violations,
|