-
Notifications
You must be signed in to change notification settings - Fork 88
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
Resolved path for axe-core/axe.min.js
is incorrect if the Cypress Config is in a sub-directory when using Cypress v10+
#134
Comments
We are also experiencing this issue |
Fun fact: it only throws this error with This is using the same config file for both commands. |
Facing the same issue, both when Environment: devDependencies:
|
still does not work with cypress 10.6 |
We are experiencing this issue on Cypress 10.3. We have a |
I'm experiencing this as well, see CI logs here: https://github.com/ismay/portfolio/actions/runs/3067878096/jobs/4954656842#step:3:266 Looking at the resolved path, it seems like that path is correct relative to my config file (which is in ./.cypress): However, judging from the error it seems like The cypress docs mention that readFile resolves relative to the config file: https://docs.cypress.io/api/commands/readfile#Arguments, at least that's how I read it: Judging from this issue the base path is actually hardcoded to the project root: cypress-io/cypress#2673 (see the related issues as well). So if that's correct, to fix this I think we have to make sure that we're resolving from the root of the project here: https://github.com/component-driven/cypress-axe/blob/master/src/index.ts#L26. See the docs here: https://nodejs.org/api/modules.html#requireresolverequest-options. Maybe https://github.com/sindresorhus/pkg-dir would be useful to resolve this. |
Here is a patch you can use to fix it with the patch-package exports.injectAxe = function () {
- var fileName = typeof (require === null || require === void 0 ? void 0 : require.resolve) === 'function'
- ? require.resolve('axe-core/axe.min.js')
- : 'node_modules/axe-core/axe.min.js';
+ var fileName = 'node_modules/axe-core/axe.min.js';
+
cy.readFile(fileName).then(function (source) {
return cy.window({ log: false }).then(function (window) {
window.eval(source); |
If that fixes it for you it would be good to submit your patch as a PR. |
@artvichi this won't work for workspaces when When install using workspace scoping packages:
if install normally
Problem only occurs on EDIT: plugin should be compiled to commonjs AND esm, also should use cypress |
This all sounds exactly as the upstream issue: cypress-io/cypress#22689. Work-around for now: cypress-io/cypress#22689 (comment) |
This PR address this issue as well #150 |
This comment was marked as spam.
This comment was marked as spam.
Hi, I'm still seeing issues with this after upgrading This is what I see in terminal when running my tests:
The file does exist in I've made the following change in my custom Cypress function that tests a11y (as indicated here):
My config files are nested as follows:
Can someone please advise? Many thanks! |
@9j0hn50n Hi, Not sure why you are using
|
Lovely, thank you @dkryaklin! I had tried But Thanks again. |
I have a similar, but slightly bizarre issue. When I try to injectAxe in an afterEach it works fine, however if the beforeEach or test fails it can't fine the file axe-core/axe.min.js. Does anyone know why that would be? Here is my checkAxe custom command: - Cypress.Commands.add('checkAxe', (wait?: number) => {
if (wait) {
cy.wait(wait);
}
cy.injectAxe();
cy.configureAxe({
rules: exceptions.map(rule => ({id: rule, enabled: false})),
standards: accessibilityStandards
});
cy.window({log: false})
.then((win: any) => {
const context = {
include: [win.document],
exclude: exclusions,
};
const rules = exceptions.reduce((result, exception) => {
result[exception] = {enabled: false};
return result;
}, {});
return cy.checkA11y(context, <any>{runOnly: accessibilityStandards, rules});
});
}); |
axe-core/axe.min.js
cannot be loaded if the Cypress config is contained in a sub directory. The resolved path traverses from the location of the config, but starts at the project root where the command was invoked.This seems to be due to
require.resolve
returning the path relative to the configuration file, whereas when running in Cypress Versions <10require.resolve
returns the path relative to the directory the initial command was invoked.So assuming a project with a directory structure of:
The path we attempt to require for
axe-core/axe.min.js
will be/home/user/dev/node_modules/axe-core/axe.min.js
.A minimum reproduction can be found using my fork of this repo.
The text was updated successfully, but these errors were encountered: