How to properly test Custom Plugins #21405
Unanswered
Erik-Outreach
asked this question in
Plugins
Replies: 0 comments
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.
-
I'm trying to write automated tests around my custom plugin, but couldn't find much documentation on how to do it, so I'm bringing my ideas and proposing a discussion topic, so we can find together what's the best approach to testing custom plugins.
The plugin I have in mind doesn't affect the cypress-driver but just the cypress-server package. So in this case, I don't need to worry about testing browser related stuff, and I see a few approaches I could use to test it:
This is the main approach I've been using but it's a bit cumbersome. For each new plugin I want to write, I need to create a folder (or reuse a single-folder approach with env variable turning plugins on and off). It also requires to expose whatever I need to assert externally, and sometimes mocha results files are suitable, but sometimes not and requires a bit of hacking (output files or something).
When a plugin that doesn't require much of cypress itself to test (node only), then you could mock some part of it. For instance for plugin I need to assert behaviour plugged to 'before:spec', so a bit of decomposition and simulating the invocation of 'before:spec' could get me there. This doesn't require the file setup and is self-contained but doesn't really test it along with cypress.
This possibility takes me to my third alternative which I find more promising.
Inspired by event-tests case, I think it could work by installing a plugin on the fly and executing the event from cypress-server package. With this, we'd have a self-contained test which tests the plugin along with cypress without all the setup from step 1.
Unfortunately cypress-server isn't made public so we can't install in node project to consume the methods.
[LR;DR]:
Thanks,
Erik Witkowski
Beta Was this translation helpful? Give feedback.
All reactions