Skip to content

Commit

Permalink
Update types to include runAxe() and configureAxe(), update axe-core …
Browse files Browse the repository at this point in the history
…to include 4.0.2 version (#4)

* feat: updated types to include runAxe and configureAxe, added configureAxe, updated axe-core to include 4.0.2 version

* feat: updated types to include runAxe and configureAxe, added configureAxe, updated axe-core to include 4.0.2 version

* docs: code review update, README.md update
  • Loading branch information
lpelypenko authored Oct 13, 2020
1 parent 0ee8ffb commit 1e672f3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The TestCafe module that allows you to use the [aXe](https://github.com/dequelab
yarn add -D axe-core @testcafe-community/axe
```

Or using npm:

```bash
npm i -D axe-core @testcafe-community/axe
```

## How to use

You can write a TestCafe test with automated accessibility checks like this.
Expand Down Expand Up @@ -38,6 +44,8 @@ If any accessibility issues are found, you will see a detailed report in the err
The `@testcafe-community/axe` module allows you to define the `context` and `options` [axe.run parameters](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axerun) in a TestCafe test.

```js
import { checkForViolations } from '@testcafe-community/axe';

test('Automated accessibility testing', async (t) => {
const context = { exclude: [['select']] };
const options = { rules: { 'html-has-lang': { enabled: false } } };
Expand All @@ -61,3 +69,19 @@ test('Automated accessibility testing', async t => {
await t.expect(violations.length === 0).ok(createReport(violations));
});
```

## Using full axe result object and axe.configure

If you prefer to use a custom reporter for axe results you can get result object using runAxe function:

```js
import { runAxe } from '@testcafe-community/axe';

fixture `TestCafe tests with Axe`
.page `http://example.com`;

test('Automated accessibility testing', async t => {
const { error, results } = await runAxe(t);
// results constant contains full axe Results object (https://www.deque.com/axe/core-documentation/api-documentation/#results-object)
});
```
22 changes: 20 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
declare module '@testcafe-community/axe' {
import { ElementContext, RunOnly, AxeResults, Result } from 'axe-core';
import { ElementContext, RunOnly, AxeResults, Result, Spec } from 'axe-core';

interface AxeCheck {
results: AxeResults;
error?: any;
}

export function runAxe(
context?: ElementContext,
options?: {
runOnly?: RunOnly;
rules?: Object;
iframes?: Boolean;
elementRef?: Boolean;
selectors?: Boolean;
}
): Promise<AxeCheck>;

export function configureAxe(spec: Spec): Promise<void>;

export function axeCheck(
t: TestController,
Expand All @@ -11,7 +29,7 @@ declare module '@testcafe-community/axe' {
elementRef?: Boolean;
selectors?: Boolean;
}
): Promise<AxeResults>;
): Promise<AxeCheck>;

export function createReport(violations: Result[]): string;

Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const runAxe = ClientFunction((context, options = {}) => {
});
});

const configureAxe = ClientFunction((spec) => {
return axe.configure(spec);
}
);

const createReport = violations => {
if (!violations.length) {
return green('0 violations found');
Expand Down Expand Up @@ -68,6 +73,7 @@ const checkForViolations = async (t, context, options) => {

module.exports = {
runAxe,
configureAxe,
axeCheck,
createReport,
checkForViolations
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"index.d.ts"
],
"peerDependencies": {
"axe-core": ">=2.2.3 <4",
"axe-core": ">=2.2.3 <=4",
"testcafe": "*"
},
"dependencies": {
Expand Down

0 comments on commit 1e672f3

Please sign in to comment.