cypress-axe: Resolved path for `axe-core/axe.min.js` is incorrect if the Cypress Config is in a sub-directory when using Cypress v10+
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 <10 require.resolve
returns the path relative to the directory the initial command was invoked.
So assuming a project with a directory structure of:
/home/user/dev/project/
- e2e/
- config/
- cypress.config.ts
- src/
- node_modules/
- package.json
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.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 19
- Comments: 18 (2 by maintainers)
Commits related to this issue
- feat: Allow to use custom axe-core location (#150) Closes #146 #134 #84 #75 — committed to component-driven/cypress-axe by dkryaklin a year ago
Lovely, thank you @dkryaklin!
I had tried
../../../node_modules/axe-core/axe.min.js
but still got the mentioned error.But
./node_modules/axe-core/axe.min.js
did the trick.Thanks again.
This all sounds exactly as the upstream issue: https://github.com/cypress-io/cypress/issues/22689. It makes no sense that all plugins in the ecosystem start patching themselves due to a bug in Cypress. Code coverage plugin is also seeing this: https://github.com/cypress-io/code-coverage/issues/586.
Work-around for now: https://github.com/cypress-io/cypress/issues/22689#issuecomment-1211732120
If that fixes it for you it would be good to submit your patch as a PR.