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.
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: npm
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ time: "23:30"
8
+ open-pull-requests-limit: 10
9
+ ignore:
10
+ - dependency-name: "@types/node"
11
+ versions:
12
+ - 15.0.0
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  [![Build Status](https://circleci.com/gh/abhinaba-ghosh/axe-playwright.svg?style=shield&branch-=master)](https://app.circleci.com/pipelines/github/abhinaba-ghosh/axe-playwright)
6
6
  [![NPM release](https://img.shields.io/npm/v/axe-playwright.svg 'NPM release')](https://www.npmjs.com/package/axe-playwright)
7
+ [![NPM Downloads](https://img.shields.io/npm/dt/axe-playwright.svg?style=flat-square)](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
- ### getViolations
127
+ ### getAxeResults
127
128
 
128
- This will run axe against the document at the point in which it is called, then return you an array of accessibility violations.
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 getViolations (axe.run)
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 keys consist of [those accepted by `axe.run`'s options argument](https://www.deque.com/axe/documentation/api-documentation/#parameters-axerun) as well as custom `includedImpacts`, `detailedReport`, and `detailedReportOptions` keys.
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
- Filtering based on impact in combination with the `skipFailures` argument allows you to introduce `axe-playwright` into tests for a legacy application without failing in CI before you have an opportunity to address accessibility issues. Ideally, you would steadily move towards stricter testing as you address issues.
149
- e-effects, such as adding custom output to the terminal.
147
+ ### getViolations
150
148
 
151
- **NOTE:** _This respects the `includedImpacts` filter and will only execute with violations that are included._
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
- The `detailedReport` key is a boolean whether to print the more detailed report `detailedReportOptions` is an object with the shape
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 accessibility violations detected on the page
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 getViolations = (page, context, options) => __awaiter(void 0, void 0, void 0, function* () {
62
+ const getAxeResults = (page, context, options) => __awaiter(void 0, void 0, void 0, function* () {
63
63
  const result = yield page.evaluate(([context, options]) => {
64
- const axeOptions = options ? options['axeOptions'] : {};
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?: Options): Promise<Result[]>
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.8",
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": "^2.0.0",
29
- "@types/jest": "^26.0.10",
30
- "@types/node": "^14.14.25",
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": "^26.6.2",
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 accessibility violations detected on the page
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 getViolations = async (
48
+ export const getAxeResults = async (
49
49
  page: Page,
50
50
  context?: ElementContext,
51
- options?: Options,
52
- ): Promise<Result[]> => {
51
+ options?: RunOptions,
52
+ ): Promise<AxeResults> => {
53
53
  const result = await page.evaluate(
54
54
  ([context, options]) => {
55
- const axeOptions: RunOptions = options ? options['axeOptions'] : {}
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,