Skip to content

Commit 3f50bdd

Browse files
committed
feat: add options for injectAxe
1 parent b6391e6 commit 3f50bdd

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ beforeEach(() => {
7676
})
7777
```
7878

79+
The `injectAxe` function receives an optional argument `injectOptions` of type `InjectOptions`.
80+
81+
This `injectOptions` object can have a property `axeCorePath` of type `string`, which allows the user to specify the file from which `axe-core` will be injected.
82+
83+
If `axeCorePath` is not provided, the function will try to resolve the path to `axe-core/axe.min.js` using the `require.resolve` function, if it is available.
84+
85+
If `require.resolve` is not available, the default path `node_modules/axe-core/axe.min.js` will be used.
86+
87+
```js
88+
beforeEach(() => {
89+
cy.visit('http://localhost:9000')
90+
cy.injectAxe({ axeCorePath: '<path-to-axe-core>' })
91+
})
92+
```
93+
7994
### cy.configureAxe
8095

8196
#### Purpose

src/index.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@ export interface Options extends axe.RunOptions {
2121
includedImpacts?: string[];
2222
}
2323

24-
export const injectAxe = () => {
24+
export interface InjectOptions {
25+
axeCorePath?: string;
26+
}
27+
28+
export const injectAxe = (injectOptions?: InjectOptions) => {
2529
const fileName =
26-
typeof require?.resolve === 'function'
30+
injectOptions?.axeCorePath ||
31+
(typeof require?.resolve === 'function'
2732
? require.resolve('axe-core/axe.min.js')
28-
: 'node_modules/axe-core/axe.min.js';
33+
: 'node_modules/axe-core/axe.min.js');
2934
cy.readFile<string>(fileName).then((source) =>
3035
cy.window({ log: false }).then((window) => {
3136
window.eval(source);

0 commit comments

Comments
 (0)