From 2d33850bb203260f86ae1ad4e3905f7757dadc5b Mon Sep 17 00:00:00 2001 From: Henry Fraser Date: Tue, 15 Nov 2022 07:55:54 +1000 Subject: [PATCH] fix: allow cypress-axe to be used when csp is set to deny eval() --- cypress/e2e/test.cy.js | 2 +- src/index.ts | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/cypress/e2e/test.cy.js b/cypress/e2e/test.cy.js index 9350f23..3a90af6 100644 --- a/cypress/e2e/test.cy.js +++ b/cypress/e2e/test.cy.js @@ -1,5 +1,5 @@ it('works!', () => { cy.visit('/'); cy.injectAxe(); - cy.checkA11y(); + cy.checkA11y('body'); }); diff --git a/src/index.ts b/src/index.ts index 89d9981..8fe6c1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import * as axe from 'axe-core'; +import axe from 'axe-core'; declare global { interface Window { @@ -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(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 = {}) => {