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

Error invoking the cy.injectAxe() command with "cypress": "^5.5.0" and "cypress-axe": "^0.10.0" #73

Open
FJLopezGarcia opened this issue Nov 3, 2020 · 16 comments
Labels
bug Something isn't working

Comments

@FJLopezGarcia
Copy link

Hi All,
I am trying to setup Ally in my project but I am getting below error running an initial/simple test:
Do you know where is the issue? is due to Cypress 5? it seems that it is supported based on the documentation.Do you know which with versions runs properly?

image

Tere you have my configuration and script:
image

image

image

@reintroducing
Copy link

Was literally just about to log the same thing. I updated from v0.9.1 to v0.10.0 and got this, only update I made to my dependencies. I'm using Cypress v5.5.0 and v0.9.1 worked perfectly with it. This update breaks it.

@sapegin sapegin added the bug Something isn't working label Nov 3, 2020
@sapegin
Copy link
Member

sapegin commented Nov 3, 2020

It does work in the example I've added to the repository. Not sure what might be different?

https://github.com/component-driven/cypress-axe/tree/master/cypress

@reintroducing
Copy link

@sapegin I'm not sure either. I just tried to set up an easily reproducible scenario using CRA and had no issues. In my case, where I do have the issues, I'm just running cypress against Storybook for a UI library I developed so nothing crazy in terms of setup. I am also using start-server-and-test like you are in the example in that project, but it does not seem to make a difference as I set up the CRA example to do the same thing. I have no clue where the disconnect could be...

@sapegin
Copy link
Member

sapegin commented Nov 4, 2020

Trying it on one of my projects with Strobyook and TypeScript, and it also works fine.

image

Do you have Babel or TypeScript or something like that on the project? Maybe the code is transpiled differently somehow...

@FJLopezGarcia
Copy link
Author

I am using TypeScript and cucumber to write the Cypress tests. (see above screenshot with my "package.json" file)

@tvararu
Copy link

tvararu commented Nov 4, 2020

We're experiencing the same issue on Cypress 4.12.0: DFE-Digital/apply-for-teacher-training-tests@44911ed

@sapegin
Copy link
Member

sapegin commented Nov 4, 2020

@tvararu how can I run it?

@reintroducing
Copy link

reintroducing commented Nov 5, 2020

@sapegin In my case, I believe I have found the source of the issue. It stems from this issue and the need to include the @cypress/browserify-preprocessor as outlined in this comment to fix it. I've attached a stripped down zip file showing this. Just run npm i && npm start after unzipping and you will see the issue show up. If you then go into cypress/plugins/index.js and comment out line 2 and 34, the tests run as expected.

Unfortunately, without that require statement, the other problem shows up thats outlined in that issue for those of us extending browserslist configs. This works fine on the prior (v0.9.1) version of cypress-axe, though.

cypress-axe-issue.zip

@sapegin sapegin pinned this issue Nov 11, 2020
@marcobeltempo
Copy link

@patheard workaround worked for me
#6 (comment)

@CharlieGreenman
Copy link

CharlieGreenman commented Nov 23, 2020

For the record, the workaround did not work for me, and this is still an issue. Wondering if we can discuss further? I am getting the error that "t is not defined"

UPDATE
Ended up rolling back my packages.

UPDATE 2
This still didn't help. Turns out issue is with webpack configuration all together. Once that was turned off, this no longer became an issue. I hope this helps, and convinced we just have to find the right configs for Webpack as a community.

@townxelliot
Copy link

We are also seeing this issue. We've downgraded to 0.9.1 (as mentioned by @reintroducing) and everything is fine. We haven't tried the work-around.

@ricardobarata
Copy link

ricardobarata commented Nov 27, 2020

Same issue.

 TypeError: require.resolve is not a function
  at Context.exports.injectAxe (http://localhost:4200/__cypress/tests?p=test/support/index.js:333:25)

Using angular 11
axe-core: 4.1.1
cypress: 6.3.0
cypress-axe: 0.12.0

Update:
After fiddling again with it @patheard workaround did work for me - just make sure

Cypress.Commands.add('injectAxe', () => {
  cy.window({ log: false }).then(window => {
      const axe = require('axe-core/axe.js');
      const script = window.document.createElement('script');
      script.innerHTML = axe.source;
      window.document.head.appendChild(script);
  })
})

is in index.js or the .js file with the code above is referenced in it.

In the end of the day is still a workaround - so we can keep the issue open :)

@brettz9
Copy link
Contributor

brettz9 commented Jan 27, 2021

Not sure if this was because I was importing my commands file from cypress/support/index.js, but I seemed to need to create a separate injectAxe in the commands file (I creatively renamed to injectAxe2) and call that instead.

@MaciekBaron
Copy link

Has anyone worked out what the issue is? I get this problem simply after updating cypress-axe to the latest version, everything works on older versions.

@callumacrae
Copy link

Same problem here - tracked it down to adding @cypress/browserify-preprocessor which was added by cypress-cucumber-preprocessor.

Workaround mentioned by @marcobeltempo fixed it: #6 (comment)

@tannerbaum
Copy link

tannerbaum commented Apr 1, 2022

This is an incredibly obvious suggestion, but I think there are a fair number of people who throw cypress/support in the .gitignore. It took me I don't know how many hours to realize thats why I was getting this error in the CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests