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 1 commit
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
2 changes: 2 additions & 0 deletions packages/jest-puppeteer-axe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ It is also possible to pass optional Axe API options to perform customized check
- `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` - options to be used by `axe.run`. See [axe-core API documentation](https://github.com/dequelabs/axe-core/blob/master/doc/API.md) for information on its structure.
gziolo marked this conversation as resolved.
Show resolved Hide resolved
- `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.
Hypnosphi marked this conversation as resolved.
Show resolved Hide resolved

```js
test( 'checks the test component with Axe excluding some button', async () => {
gziolo marked this conversation as resolved.
Show resolved Hide resolved
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 Axe API options.
gziolo marked this conversation as resolved.
Show resolved Hide resolved
* @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 Options to be used by axe.run.
gziolo marked this conversation as resolved.
Show resolved Hide resolved
* @param {?Axe.Spec} params.config Axe configuration object.
*
* @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