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

Use Cypress plugins with synpress? #346

Closed
cs-balazs opened this issue Feb 28, 2022 · 4 comments
Closed

Use Cypress plugins with synpress? #346

cs-balazs opened this issue Feb 28, 2022 · 4 comments

Comments

@cs-balazs
Copy link

Is it possible to use Cypress plugins?
I defined these in cypress.json:

{
  "supportFile": "cypress/support/index.js",
  "pluginsFile": "cypress/plugins/index.js",
}

But the plugins only seem to be loaded when using synpress open not with synpress run.
I would like to use cypress-file-upload and custom commands.

I also can't see any plugin-related folders is the example project structure in the README.

@maxhoheiser
Copy link
Contributor

I think currently the issue is that synpress is not loading the cypress index.js, since I can also not define commands there, therefor plugins defined there are also not taken into consideration, my workaround is to use a forked version of synpress currently and modify the synpress index.js to my needs

@cs-balazs
Copy link
Author

I think currently the issue is that synpress is not loading the cypress index.js, since I can also not define commands there, therefor plugins defined there are also not taken into consideration, my workaround is to use a forked version of synpress currently and modify the synpress index.js to my needs

Thanks for the response! I ended up doing the following as a workaround:
Plugins file (cypress/plugins/index.js in my case):

import synpressPlugins from "@synthetixio/synpress/plugins"

module.exports = (on, config) => {
  synpressPlugins(on, config)
}

Support file (cypress/support/index.js in my case):

import "./commands"
import "@synthetixio/synpress/support"

I'm passing this option to synpress run: --config supportFile='cypress/support/index.js',pluginsFile='cypress/plugins/index.js'.
Commands defined in cypress/support/commands.js do get loaded this way. I'm guessing plugins like cypress-file-upload also work, but couldn't test it yet.

@maxhoheiser
Copy link
Contributor

Nice workaround!
I tried something similar too, but instead of directly passing it into the synpress run, I specified the supportFile in my synpress.json configuration file like so:

{
...
  "supportFile": "support/index.js"
}

And I pass the config file to the synpress run like so: synpress run -cf synpress.js - but that is not working 🤔

@cs-balazs
Copy link
Author

That's how I also tried originally. For some reason this way the commands only seemed to load with synpress open.
I just tried cypress-file-upload with the workaround I posted, and it also works, however, I also needed to pass fixturesFolder='cypress/fixtures' in my synpress run command, as that one also seems to be ignored when defined in the config file.

The whole command looks like this:
synpress run --configFile cypress.json --config supportFile='cypress/support/index.js',pluginsFile='cypress/plugins/index.js',fixturesFolder='cypress/fixtures' -b chromium

Closing the issue, since my original problem has been resolved.

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

No branches or pull requests

2 participants