Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-puppeteer-axe: add options and config parameters #18712

Merged
merged 3 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/jest-puppeteer-axe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ test( 'checks the test page with Axe', async () => {
} );
```

It is also possible to pass optional Axe API options to perform customized check:
It is also possible to pass optional params which allow Axe API to perform customized checks:
- `include` - CSS selector(s) to to add the list of elements to include in analysis.
- `exclude` - CSS selector(s) to to add the list of elements to exclude from analysis.
- `disabledRules` - the list of [Axe rules](https://github.com/dequelabs/axe-core/blob/master/doc/rule-descriptions.md) to skip from verification.
- `options` - a flexible way to configure how Axe run operates. See [axe-core API documentation](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#options-parameter) for information on the object structure.
- `config` - Axe configuration object. See [axe-core API documentation](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axeconfigure) for documentation on the object structure.

```js
test( 'checks the test component with Axe excluding some button', async () => {
Expand All @@ -52,6 +54,8 @@ test( 'checks the test component with Axe excluding some button', async () => {
include: '.test-component',
exclude: '.some-button',
disabledRules: [ 'aria-allowed-role' ],
options: { iframes: false },
config: { reporter: 'raw' },
} );
} );
```
Expand Down
26 changes: 18 additions & 8 deletions packages/jest-puppeteer-axe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ function formatViolations( violations ) {
*
* @see https://github.com/dequelabs/axe-puppeteer
*
* @param {puppeteer.Page} page Puppeteer's page instance.
* @param {?Object} params Optional Axe API options.
* @param {?string|Array} params.include CSS selector(s) to add to the list of elements
* to include in analysis.
* @param {?string|Array} params.exclude CSS selector(s) to add to the list of elements
* to exclude from analysis.
* @param {?Array} params.disabledRules The list of Axe rules to skip from verification.
* @param {puppeteer.Page} page Puppeteer's page instance.
* @param {?Object} params Optional params that allow better control over Axe API.
* @param {?string|Array} params.include CSS selector(s) to add to the list of elements
* to include in analysis.
* @param {?string|Array} params.exclude CSS selector(s) to add to the list of elements
* to exclude from analysis.
* @param {?Array} params.disabledRules The list of Axe rules to skip from verification.
* @param {?Axe.RunOptions} params.options A flexible way to configure how Axe run operates, see https://github.com/dequelabs/axe-core/blob/master/doc/API.md#options-parameter.
* @param {?Axe.Spec} params.config Axe configuration object, see https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axeconfigure.
*
* @return {Object} A matcher object with two keys `pass` and `message`.
*/
async function toPassAxeTests( page, { include, exclude, disabledRules } = {} ) {
async function toPassAxeTests( page, { include, exclude, disabledRules, options, config } = {} ) {
const axe = new AxePuppeteer( page );

if ( include ) {
Expand All @@ -74,10 +76,18 @@ async function toPassAxeTests( page, { include, exclude, disabledRules } = {} )
axe.exclude( exclude );
}

if ( options ) {
axe.options( options );
}

if ( disabledRules ) {
axe.disableRules( disabledRules );
}

if ( config ) {
axe.configure( config );
}

const { violations } = await axe.analyze();

const pass = violations.length === 0;
Expand Down