Skip to content

Commit

Permalink
fix: allow cypress-axe to be used when csp is set to deny eval()
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Fraser committed Nov 14, 2022
1 parent d280f0e commit 2d33850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/test.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
it('works!', () => {
cy.visit('/');
cy.injectAxe();
cy.checkA11y();
cy.checkA11y('body');
});
14 changes: 4 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as axe from 'axe-core';
import axe from 'axe-core';

declare global {
interface Window {
Expand All @@ -22,15 +22,9 @@ export interface Options extends axe.RunOptions {
}

export const injectAxe = () => {
const fileName =
typeof require?.resolve === 'function'
? require.resolve('axe-core/axe.min.js')
: 'node_modules/axe-core/axe.min.js';
cy.readFile<string>(fileName).then((source) =>
cy.window({ log: false }).then((window) => {
window.eval(source);
})
);
cy.window({ log: false }).then((window) => {
window.axe = axe;
})
};

export const configureAxe = (configurationOptions = {}) => {
Expand Down

0 comments on commit 2d33850

Please sign in to comment.