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

Weird error after initial setup #82

Closed
craig-dae opened this issue Jan 11, 2021 · 16 comments
Closed

Weird error after initial setup #82

craig-dae opened this issue Jan 11, 2021 · 16 comments
Labels

Comments

@craig-dae
Copy link

craig-dae commented Jan 11, 2021

cy.readFile() must be passed a non-empty string as its 1st argument. You passed: 146.Learn more

This happens after finishing setup and trying to run a sample test.

This is in my command that I use to login:

    .then((url) => {
      cy.intercept('api/users/user/profile/').as('login');
      cy.visit(url);
      cy.wait('@login');
      cy.injectAxe();
    }),

Error happens on the cy.injectAxe() line.

Thanks!

@craig-dae
Copy link
Author

This is what the relevant section of code is transpiling to. Note that, this time around, it's 144 instead of 146.

exports.configureAxe = exports.injectAxe = void 0;
exports.injectAxe = function () {
    cy.readFile(/*require.resolve*/(144)).then(function (source) {
        return cy.window({ log: false }).then(function (window) {
            window.eval(source);
        });
    });
};

@craig-dae
Copy link
Author

craig-dae commented Jan 12, 2021

Tried rolling back to version 0.9.1, which seemed to be the last version people used before they started getting errors, and I get exports is not defined. Also note that this is the same error I get if I keep 0.12.1, and use the workaround located here: #6 (comment)

I'm going to leave this branch open and move away from axe. If you guys can help, that'd be great. If not, we will not be able to use axe. Thanks

@Sadorus
Copy link

Sadorus commented Feb 1, 2021

@craig-dae Did you fix the issue? I have the same problem and any workarounds don't work for me.

@sshaar08
Copy link
Contributor

@Sadorus and @craig-dae i had the same issue my solve was to pin "axe-core": "4.0.2", and "cypress-axe": "0.9.1",

then I was able to get the violations

@bstruthers
Copy link

I was able to work around this by creating my own injectAxe method in my tests.

const injectAxe = () => {
  //cy.injectAxe();
  // cy.injectAxe is currently broken. https://github.com/component-driven/cypress-axe/issues/82

  // Creating our own injection logic
  cy.readFile('../../node_modules/axe-core/axe.min.js').then((source) => {
    return cy.window({ log: false }).then((window) => {
        window.eval(source);
    });
  });
};

Then instead of calling cy.injectAxe(), I call my own method to inject the script.

@sshaar08
Copy link
Contributor

i submitted a pr here: #86 this should fix it similarly to other plugins with the same issue. seems to be a typescript issue

@github-actions
Copy link

🎉 This issue has been resolved in version 0.12.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@JessicaSachs
Copy link

JessicaSachs commented Mar 23, 2021

There's an issue with this. It crashes if require is undefined... Which happens if the webpack config doesn't transpile node_modules. This is particularly an issue inside of Cypress component testing

@James-Vanguard
Copy link

I am still getting this error on version 0.12.2

@sshaar08
Copy link
Contributor

can you edit to this commit to see if it solves your issue: 3dac12c I changed the second check, but may solve your issue

@guilhermenasszup
Copy link

I'm calling injectAxe inside beforeEach hook, but I'm still getting this error:

cy.readFile() must be passed a non-empty string as its 1st argument. You passed: 190.

Because this error occurred during a before each hook we are skipping the remaining tests in the current suite: Home integration tests

Inside node_modules folder, I checked the index.js and the error occurs here:
image

@DannyvanHolten
Copy link

This issue is not resolved when using cypress-axe 0.13.0 and axe-core 4.3.5

When I'm seeing this I'm even wondering if this is still being maintained?

@soniajains
Copy link

Yes, this issue still exists with the latest version, we tried calling our own method to inject the script.

const injectAxe = () => {

cy.readFile('../../node_modules/axe-core/axe.min.js').then((source) => {
return cy.window({ log: false }).then((window) => {
window.eval(source);
});
});
};

@moizang
Copy link

moizang commented Dec 8, 2021

Similar issue encountered today using cypress-axe 0.13.0, this issue should probably be re-opened

@mhulse
Copy link

mhulse commented Jul 11, 2022

Seeing this with "cypress-axe": "^0.14.0", and "axe-core": "^4.4.2",

UPDATE: After upgrading to @cypress/webpack-preprocessor to the latest version, the problem I was having went away. Not sure if that will help anyone else, but thought I'd share anyway.

@leads
Copy link

leads commented Feb 21, 2023

I was able to work around this by creating my own injectAxe method in my tests.

const injectAxe = () => {
  //cy.injectAxe();
  // cy.injectAxe is currently broken. https://github.com/component-driven/cypress-axe/issues/82

  // Creating our own injection logic
  cy.readFile('../../node_modules/axe-core/axe.min.js').then((source) => {
    return cy.window({ log: false }).then((window) => {
        window.eval(source);
    });
  });
};

Then instead of calling cy.injectAxe(), I call my own method to inject the script.

Two years later and I've just implemented this and it's fixed the issue. Using cypress ina nx setup, versions are:

"axe-core": "^4.6.3", "cypress-axe": "^1.3.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests