axe-playwright 1.1.12 → 1.2.3
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/README.md +37 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +18 -8
- package/dist/types.d.ts +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -95,7 +95,7 @@ The `page` instance of `playwright`.
|
|
|
95
95
|
|
|
96
96
|
Defines the scope of the analysis - the part of the DOM that you would like to analyze. This will typically be the document or a specific selector such as class name, ID, selector, etc.
|
|
97
97
|
|
|
98
|
-
#####
|
|
98
|
+
##### axeOptions (optional)
|
|
99
99
|
|
|
100
100
|
Set of options passed into rules or checks, temporarily modifying them. This contrasts with axe.configure, which is more permanent.
|
|
101
101
|
|
|
@@ -120,12 +120,19 @@ The `verbose` key is a boolean to whether to print the message `No accessibility
|
|
|
120
120
|
|
|
121
121
|
##### reporter (optional)
|
|
122
122
|
|
|
123
|
-
A class instance that implements the `Reporter` interface or values `default` and `
|
|
123
|
+
A class instance that implements the `Reporter` interface or values `default`, `v2` and `html`. Custom reporter instances can be supplied to override default reporting behaviour dictated by `DefaultTerminalReporter` set by the value `default`. `v2` is the new TerminalReporter inspired by the reports from [jest-axe](https://github.com/nickcolley/jest-axe). `html` reporter will generate external HTML file.
|
|
124
|
+
|
|
125
|
+
Note! `html` reporter will disable printed to logs violations.
|
|
124
126
|
|
|
125
127
|
##### skipFailures (optional, defaults to false)
|
|
126
128
|
|
|
127
129
|
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.
|
|
128
130
|
|
|
131
|
+
##### options (dedicated for axe-html-reporter)
|
|
132
|
+
|
|
133
|
+
Options dedicated for HTML reporter.
|
|
134
|
+
[axe-html-reporter](https://www.npmjs.com/package/axe-html-reporter)
|
|
135
|
+
|
|
129
136
|
### getAxeResults
|
|
130
137
|
|
|
131
138
|
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`.
|
|
@@ -280,6 +287,34 @@ describe('Playwright web page accessibility test', () => {
|
|
|
280
287
|
|
|
281
288
|

|
|
282
289
|
|
|
290
|
+
#### HTML Report
|
|
291
|
+
|
|
292
|
+
Thanks to [axe-html-reporter](https://www.npmjs.com/package/axe-html-reporter) you can generate HTML report(s).
|
|
293
|
+
From default HTML file(s) will be generated under `/artifacts/accessibilityReport.html`.
|
|
294
|
+
Report's options can customized from `checkAlly` level:
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
await checkA11y(
|
|
298
|
+
page,
|
|
299
|
+
'form',
|
|
300
|
+
{
|
|
301
|
+
axeOptions: {
|
|
302
|
+
runOnly: {
|
|
303
|
+
type: 'tag',
|
|
304
|
+
values: ['wcag2a'],
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
true, 'default',
|
|
309
|
+
{
|
|
310
|
+
outputDirPath: 'results',
|
|
311
|
+
outputDir: 'accessibility',
|
|
312
|
+
reportFileName: 'accessibility-audit.html'
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
|
|
283
318
|
## Before you Go
|
|
284
319
|
|
|
285
320
|
If it works for you , leave a [Star](https://github.com/abhinaba-ghosh/axe-playwright)! :star:
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Page } from 'playwright';
|
|
2
2
|
import { AxeResults, ElementContext, Result, RunOptions } from 'axe-core';
|
|
3
3
|
import DefaultTerminalReporter from './reporter/defaultTerminalReporter';
|
|
4
|
-
import Reporter, { ConfigOptions,
|
|
4
|
+
import Reporter, { ConfigOptions, AxeOptions } from './types';
|
|
5
|
+
import { Options } from 'axe-html-reporter';
|
|
5
6
|
declare global {
|
|
6
7
|
interface Window {
|
|
7
8
|
axe: any;
|
|
@@ -46,9 +47,10 @@ export declare const reportViolations: (violations: Result[], reporter: Reporter
|
|
|
46
47
|
* Performs Axe validations
|
|
47
48
|
* @param page
|
|
48
49
|
* @param context
|
|
49
|
-
* @param
|
|
50
|
+
* @param axeOptions
|
|
50
51
|
* @param skipFailures
|
|
51
52
|
* @param reporter
|
|
53
|
+
* @param options
|
|
52
54
|
*/
|
|
53
|
-
export declare const checkA11y: (page: Page, context?: ElementContext | undefined,
|
|
55
|
+
export declare const checkA11y: (page: Page, context?: ElementContext | undefined, axeOptions?: AxeOptions | undefined, skipFailures?: boolean, reporter?: Reporter | 'default' | 'html' | 'v2', options?: Options | undefined) => Promise<void>;
|
|
54
56
|
export { DefaultTerminalReporter };
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ const utils_1 = require("./utils");
|
|
|
41
41
|
const defaultTerminalReporter_1 = __importDefault(require("./reporter/defaultTerminalReporter"));
|
|
42
42
|
exports.DefaultTerminalReporter = defaultTerminalReporter_1.default;
|
|
43
43
|
const terminalReporterV2_1 = __importDefault(require("./reporter/terminalReporterV2"));
|
|
44
|
+
const axe_html_reporter_1 = require("axe-html-reporter");
|
|
44
45
|
/**
|
|
45
46
|
* Injects axe executable commands in the active window
|
|
46
47
|
* @param page
|
|
@@ -96,26 +97,35 @@ exports.reportViolations = reportViolations;
|
|
|
96
97
|
* Performs Axe validations
|
|
97
98
|
* @param page
|
|
98
99
|
* @param context
|
|
99
|
-
* @param
|
|
100
|
+
* @param axeOptions
|
|
100
101
|
* @param skipFailures
|
|
101
102
|
* @param reporter
|
|
103
|
+
* @param options
|
|
102
104
|
*/
|
|
103
|
-
const checkA11y = (page, context = undefined,
|
|
105
|
+
const checkA11y = (page, context = undefined, axeOptions = undefined, skipFailures = false, reporter = 'default', options = undefined) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
106
|
var _a, _b, _c;
|
|
105
|
-
const violations = yield (0, exports.getViolations)(page, context,
|
|
106
|
-
const impactedViolations = (0, utils_1.getImpactedViolations)(violations,
|
|
107
|
+
const violations = yield (0, exports.getViolations)(page, context, axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.axeOptions);
|
|
108
|
+
const impactedViolations = (0, utils_1.getImpactedViolations)(violations, axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.includedImpacts);
|
|
107
109
|
let reporterWithOptions;
|
|
108
110
|
if (reporter === 'default') {
|
|
109
|
-
reporterWithOptions = new defaultTerminalReporter_1.default(
|
|
111
|
+
reporterWithOptions = new defaultTerminalReporter_1.default(axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.detailedReport, (_a = axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.detailedReportOptions) === null || _a === void 0 ? void 0 : _a.html, (_b = axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.verbose) !== null && _b !== void 0 ? _b : true);
|
|
110
112
|
}
|
|
111
113
|
else if (reporter === 'v2') {
|
|
112
|
-
reporterWithOptions = new terminalReporterV2_1.default((_c =
|
|
114
|
+
reporterWithOptions = new terminalReporterV2_1.default((_c = axeOptions === null || axeOptions === void 0 ? void 0 : axeOptions.verbose) !== null && _c !== void 0 ? _c : false);
|
|
115
|
+
}
|
|
116
|
+
else if (reporter === 'html') {
|
|
117
|
+
if (violations.length > 0) {
|
|
118
|
+
yield (0, axe_html_reporter_1.createHtmlReport)({ results: { violations }, options });
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
console.log("There were no violations to save in report");
|
|
113
122
|
}
|
|
114
123
|
else {
|
|
115
124
|
reporterWithOptions = reporter;
|
|
116
125
|
}
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
if (reporter !== 'html')
|
|
127
|
+
yield (0, exports.reportViolations)(impactedViolations, reporterWithOptions);
|
|
128
|
+
if (reporter === 'v2' || reporter !== 'html')
|
|
119
129
|
(0, utils_1.testResultDependsOnViolations)(impactedViolations, skipFailures);
|
|
120
130
|
});
|
|
121
131
|
exports.checkA11y = checkA11y;
|
package/dist/types.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface ConfigOptions {
|
|
|
35
35
|
export default interface Reporter {
|
|
36
36
|
report(violations: Result[]): Promise<void>;
|
|
37
37
|
}
|
|
38
|
-
export type
|
|
38
|
+
export type AxeOptions = {
|
|
39
39
|
includedImpacts?: ImpactValue[];
|
|
40
40
|
detailedReport?: boolean;
|
|
41
41
|
detailedReportOptions?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe-playwright",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Custom Playwright commands to inject axe-core and test for a11y",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"picocolors": "^1.0.0",
|
|
44
|
-
"axe-core": "^4.5.1"
|
|
44
|
+
"axe-core": "^4.5.1",
|
|
45
|
+
"axe-html-reporter": "2.2.3"
|
|
45
46
|
},
|
|
46
47
|
"repository": {
|
|
47
48
|
"type": "git",
|