Problem/Motivation
DDEV is a deservedly popular way to develop locally
Our Cypress integration needs to work better with DDEV. This added functionality should probably be in the form of a ddev addon https://github.com/ddev/ddev-addon-template , and not anything DDEV-specfic in the Experience Builder codebase outside of possibly adding a link to the DDEV addon in a README.
What to do
Things it will need to do:
- Install the Cypress system dependencies: https://docs.cypress.io/guides/getting-started/installing-cypress#Linux-... (fairly sure but not 100% certain that Cypress needs to run on the same image as Drupal's PHP to use the setup scripts originally created for Nightwatch. Any existing solutions I've found run cypress on a separate image designed for Cypress use ).
- The Cypress test runner app needs to be available on the dev machine even though it runs inside the container. This article has info on making GUI applications run from a container available to use: https://sourabhbajaj.com/blog/2017/02/07/gui-applications-docker-mac/?ref=cypress-io.ghost.io
- A Cypress specific ddev command so the tests can be run without having to ssh into the container.
Cypress also has documentation on how it can be run in Docker https://www.cypress.io/blog/2019/05/02/run-cypress-with-a-single-docker-command.
The DDEV Nightwatch Addon can be a helpful reference: https://github.com/justafish/ddev-drupal-core-dev
The DDEV Cypress Addon is perhaps an even more helpful reference, but probably can't work as-is due to it running Cypress on a dedicated image - not the one running Drupal. If this isn't a limitation then great!
Issue fork experience_builder-3458369
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rkollerThere is already an existing cypress addon for ddev: https://github.com/tyler36/ddev-cypress Perhaps that is already providing everything needed?
Comment #3
lauriiiComment #4
lauriiiComment #5
bnjmnmComment #6
bnjmnmThe DDEV + Cypress addon mentioned in #2 looks like a good thing to reference, but I'm not sure it can be used as-is. It does not appearlike it is adding Cypress dependencies to the image Drupal runs on, but instead is running Cypress from a dedicated image. Because of the setup scripts (same PHP scripts as what Nightwatch uses) I'm pretty sure /em> Cypress needs to be running on the same "machine" as Drupal's PHP but happy to find out otherwise
Comment #7
bnjmnmThe following steps is from a new DDEV site to Cypress + DDDEV working at the same level Nightwatch Currently does (with no access to the test runner app)
This also makes running other core tests possible, too.
Things that still need to be done:
poweroff, but this is a good step in the right directionddev execComment #8
wim leersComment #9
lauriiiComment #10
traviscarden commented@bnjmnm, I'm working on a POC at https://github.com/TravisCarden/xb.ddev.site. The approach is a little crude, but I decided to favor time-to-value over polish. Care to give it a peek and we can discuss it? Just look at the README for instructions.
Comment #11
bnjmnmThe Repo linked in #10 looks like (but perhaps I'm wrong) something that sets up an entire instance, but the goal here is ti make an addon (probably based on the template) that can be applied to an existing ddev instance - basically the Cypress equivalent of the Nightwatch DDEV addon mentioned in the issue summary.
Unless the Github search isn't working right I'm also not seeing the Cypress system dependencies being installed, which are needed for Cypress to run at all. The Cypress documentation page on system dependencies mentioned in the issue summary provides more details, and the following line is how the dependencies are added in the GitlabCI runs:
apt-get -y update; ddev exec sudo apt-get -y install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfbComment #12
wim leersComment #13
traviscarden commentedYes, thanks, @bnjmnm. POC, as I say. 🙂 I'm trying to get a working, repeatable setup before I try to extract the components into an add-on. I want to solve one problem at a time so I know, for example, whether tests fail because my addon isn't working or because my starting assumptions are wrong.
The Cypress system dependencies are being installed in
.ddev/config.yaml.I encapsulated the Cypress command in a simple
ddev cypresscommand.The setup itself seems to be working, but that the tests fail, suggesting I'm missing something fundamental. I'll give it another look and then reach out to you to set me straight. 😉
Comment #14
wim leersCan you post the output showing the test failures here, @TravisCarden? 🙏 I do not have
ddevinstalled, plus providing that context here will be helpful for posterity anyway 😊Comment #15
bnjmnmFor me at least, pasting the snippet in #7 takes me all the way to Cypress tests passing on a DDEV site. If
ddev auth sshhasn't been run recently that might be necessary to do theapt-getIt would be helpful for me to know where specifically that snippet fails on your machine, or if it fails at all.
Comment #16
traviscarden commentedAh, your snippet works for me now, @bnjmnm. (It probably worked the first time, but as I recall, tests were actually failing upstream at that time, so I couldn't be sure.) That gets me moving forward; thanks.
Comment #17
traviscarden commentedAlright, @bnjmnm. I have a working add-on, including dependency setup and a simple
ddev cypresscommand, at https://github.com/TravisCarden/ddev-drupal-xb-dev. I have a little more to do in the way of polish, but it's basically functionally complete. You can test it, if you like, while I put on the finishing touches.Comment #18
traviscarden commentedA handful of people have tested the add-on, and it seems to be working well. There have been a few hiccups that seem to be mostly about individuals' DDEV installations (e.g., out of date versions), but the add-on itself is working.
I'm currently working on adding support for the Cypress App (UI). I've never used it myself, so I'm getting up to speed on it at the same time.
Comment #19
wim leers🥳 Thanks for the update, @TravisCarden!
Comment #20
traviscarden commentedA few more people have successfully tested the add-on. One person had a mysterious problem that was solved by updating his version of DDEV. If we identify an actual minimum version dependency, it can be explicitly declared in the add-on config, just like you would a Drupal module. Another person is having trouble with certificates in the container preventing Composer operations.
In the meantime, I've fixed an issue with the Cypress binary getting cached on the host machine and becoming unavailable after restarting DDEV. I also added a symlink in the project root to the module (deep down in
web/modules/contrib/experience_builder) for convenient access. You'll automatically get the latest state when you follow the installation instructions at https://github.com/TravisCarden/ddev-drupal-xb-dev#installation.I'm continuing to work on Cypress UI integration.
Comment #21
traviscarden commentedI've been taking a lot of rabbit trails... Running the UI app from outside the container is complicated. (Thanks to @bnjmnm for showing me how it's at least supposed to look when it works.) I've tried a few approaches that I hoped would limit the number of dependencies on the host, but it doesn't look like I'll get away without at least one--XQuartz. In the meantime, I renamed the Cypress headless tests command to
ddev xb-cypress-runand added addev xb-npm-cicommand to runnpm cito rebuild front-end assets when you make or pull down changes.Comment #22
wim leersIt's been >1.5 week without an update here and 2 weeks since the last commit to https://github.com/TravisCarden/ddev-drupal-xb-dev. Can you enlighten the 9 followers of this issue, @TravisCarden? 🙏
Comment #23
wim leersTIL that @TravisCarden has been sick for the past 1.5 week! 😞🤗
Comment #24
traviscarden commentedThanks, @Wim Leers. I wasn't completely gone during that time, but I wasn't terribly productive, either. Obviously, I could have kept you updated better; sorry. My scrum team knew I wasn't dead. 😛 At any rate...
I have a functionally complete alpha ready for testing--including the interactive Cypress mode that was absent from previous versions. It now takes just four commands to set up a new environment and a single command to run Cypress on demand. See the updated instructions at https://github.com/TravisCarden/ddev-drupal-xb-dev.
Comment #25
wim leersThat's truly all I knew! 🤣
Let's get @jessebaker to test this! 🤞
Comment #26
balintbrewsI ran with the instructions and hit the following error, which matches what @jessebaker experienced:
I found a thread in a similar project that has seemingly relevant comments to this error:
tyler36/ddev-cypress#26. I tried to run things in Rosetta with a modifieddocker-compose.local.yamlto setplatformtolinux/amd64as mentioned in a comment, but that didn't help either.Comment #27
wim leers😬
Comment #28
traviscarden commentedThanks for the error output, @balintbrews; that was helpful. I identified a necessary setup step that was missing from the README: https://github.com/TravisCarden/ddev-drupal-xb-dev#prerequisites-xquartz. Please try again. I don't expect it to get you all the way there, but I know it will get your farther. @jessebaker and I also found it necessary to update his installation of DDEV at one point, so you might do that, too, just for good measure. I'll keep looking around to see what (I assume) is still missing from my setup instructions. I might reach out to someone else in my timezone, too. Let me know what you find.
Comment #29
traviscarden commentedKind thanks to @mayankguptadotcom for helping me test this more today. Here's the error output he's getting:
I think I'm going to post an issue in the DDEV GitHub queue and see if I can get some assistance there.
Comment #30
traviscarden commentedI've posted a question to the DDEV issue queue at https://github.com/orgs/ddev/discussions/6472.
Comment #31
mayankguptadotcom commentedI was facing the issue in running cypress. Since I was using orbstack - I had to change the DISPLAY variable in /.ddev/config.drupal-xb-dev.yaml to the following :
- DISPLAY=host.orb.internal:0
I had to also ensure that xquartz -> Settings -> Security -> Allow connections from network clients was checked.
Comment #32
traviscarden commentedI want to call out that @pavlosdan and @chrisfromredfin have been helping me a lot with debugging. I'm going to ask them to comment here and request that they get issue credit for sure. :)
Comment #33
pavlosdanDuring the initial setup after setting:
xquartz -> Settings -> Security -> Allow connections from network clients was checked.
I had not restarted XQuartz and the debug.sh script was failing. Once I restarted XQuartz and manually trying to run
Cypress finally started.
Running from the script again, the script kept failing with:
Adjusted debug script to open XQuartz first and give it a small delay to give it a chance to initialize before running xforce +
that helped and cypress is now running successfully.
Without the delay even if i run XQuartz before xforce + i would still get the unable to open display error.
The bottom of my debug.sh script now looks like:
And it runs successfully.
Comment #34
chrisfromredfinThis was a bit of a fun experiment! Issues were definitely around XQuartz config not being set up by default to accept network connections over TCP.
Once that was sorted it seemed to work, with the caveat we had with Maynak that his host.docker.internal alias wasnt working (but host.orb was).
Comment #35
traviscarden commentedWe've got it working for everyone now! Some people were just overlooking some of the installation steps, so I've called those out more prominently in the README. There was a special requirement for Orbstack--over and against Colima or Docker Desktop, for example--so I documented that. And I added an execution delay to accommodate people whose machines were apparently a little slower starting XQuartz. I also added a "FAQ & known issues" section and generally expanded the documentation based on what we've learned. Assigning to @jessebaker for review.
Comment #36
wim leersThis needs to update
ui/README.md, to expand on what #3465241: Add Cypress test runner instructions to UI readme added last week. #3465241 presumed a "bare metal" installation, this should expand what that added to distinguish between "bare metal" andddev.But … meanwhile, @jessebaker can review this for sure!
Comment #38
traviscarden commented👆 Something like this, @Wim Leers?
Assigning back to @jessebaker for review of the add-on itself.
Comment #39
wim leersYes, thanks!
@jessebaker: up to you to do the final pass and actually merge this! (I already credited everyone who contributed — thank you! 🙏)
Comment #42
jessebaker commented