Absolute include paths not working properly after 10.7.0 upgrade #23713
Unanswered
grivard
asked this question in
Questions and Help
Replies: 1 comment 19 replies
-
I tried this on linux and it's working fine: $ cat /tmp/blah.js
export default (on, config) => {
console.log('ok')
return config
}
$ cat cypress.config.ts
import { defineConfig } from 'cypress'
export default defineConfig({
fixturesFolder: false,
e2e: {
setupNodeEvents(on, config) {
const blah = require('/tmp/blah.js')
return blah.default // need to do this for es modules
},
baseUrl: 'http://localhost:8888',
},
}) I wonder if it's windows specific? Or I am misunderstanding the instructions? Another way you can make an absolute path (and be sure it's really absolute) is setupNodeEvents (on, config) {
const absPluginsPath = path.join(config.projectRoot, "cypress", "plugins")
}
I don't see any documentation on how Cypress handled absolute paths w.r.t |
Beta Was this translation helpful? Give feedback.
19 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm having a problem with my Cypress upgrade (9.6.0 to 10.7.0) and looking for some help or advice. After upgrading, absolute paths seem to be partially broken. I say partially because they work fine when my config file is at the project root, but I get errors when it's nested in a folder, where I need it to be (we have several config files for different test environments).
Our test configuration (from project root) was like this for 9.6.0:
cypress.config.json <-- see note* below
config*.json <-- .json config files
integration\various_hierarchies*.js <-- these are the spec files, which use absolute paths to include library files
support*.js <-- these are the said library files, which also use absolute paths to include other library files
*Normally, we don't have a cypress.config at project root. I moved one of the other files from config and renamed it cypress.config.json so that Cypress would modify it for me on upgrade. It did and the subset of tests I tried using that configuration ran as expected.
cypress.config.js <-- file created by Cypress from cypress.config.json, worked out of the box. Plugins were handled like this:
setupNodeEvents(on, config) { return require('./elsag/plugins')(on, config) },
I did experiment with setting up the plugins directly and bypassing plugins.index.js, but since we have multiple config files and this works, it seems like a better solution so I left it as is.
Except that I wanted it to be an absolute path, so I removed the leading . - which caused Cypress to fail with the following error:

I restored the relative path to cypress.config.js, copied the file to config/ and renamed it, and adjusted its relative path for the plugins location.
With that setup, my spec files work, including plugins. That is, unless they include a library using absolute paths (which most of them do of course) in which case I'll get this error:

It goes on to list other files that truly do not exist, but /elsag/support/audit-library.js most certainly does exist, assuming that / signifies project root.
The project root is 'C:\Workspace\Testing\Functional Testing' and 'C:\Workspace\Testing\Functional Testing\elsag\support\audit-library.js' does exist. And it will be found and will work, as long as I reference it using a relative path.
Note that in the error above, Cypress seems to be looking for the file in the integration folder, where it does not exist. 'C:\Workspace\Testing\Functional Testing\elsag\integration\elsag\support\audit-library.js' does not exist.
Spec files that include libraries using absolute paths work just fine, as long as my config file is at the root. It doesn't need to be named cypress.config.js, as long as it lives at project root.
Does anybody understand what's going on here? Thanks for taking the time to read this in any case.
Beta Was this translation helpful? Give feedback.
All reactions