From 53432eedb6830fee2cb48afad1bbfd921156021b Mon Sep 17 00:00:00 2001 From: Christian Lopez Espinola Date: Wed, 12 Mar 2025 05:12:28 +0100 Subject: [PATCH 1/5] Instructions and commands for running on Windows+WSL2 --- README.md | 10 ++++++++- commands/host/xb-cypress | 46 +++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 06caac2..6164d13 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,9 @@ Update the Experience Builder module clone just like you would any other Git rep ## Cypress Experience Builder uses [Cypress](https://www.cypress.io/) for front-end testing. It is currently only supported on macOS. +Linux and Windows with WSL2 might work with the instructions below. -### Setup +### Setup for MacOS > Carefully follow the below XQuartz configuration steps after installing it. Failure to do so will result in frustrating, difficult to debug problems. @@ -108,6 +109,13 @@ Configure XQuartz to allow connections from the host: ![XQuartz Preferences dialog](resources/xquartz-settings.png) +### Setup for Windows using ddev inside WSL2 + +> This is experimental. + +Install [VcXsrv Windows X Server](https://sourceforge.net/projects/vcxsrv) in the default "C:/Program Files" location. +You might need to restart your system afterwards. + ### Usage Run Cypress tests interactively: diff --git a/commands/host/xb-cypress b/commands/host/xb-cypress index 2264a43..f1de883 100755 --- a/commands/host/xb-cypress +++ b/commands/host/xb-cypress @@ -7,12 +7,13 @@ ## Aliases: cypress,cy ## Flags: [] ## AutocompleteTerms: ["component","open","run"] -## OSTypes: darwin +## OSTypes: darwin,linux ## ExecRaw: true cd "$(dirname "$0")" || exit 1 CYPRESS_BIN="$(dirname "$0")/../../../web/modules/contrib/experience_builder/ui/node_modules/.bin/cypress" +CYPRESS_BIN_INSIDE="/var/www/html/web/modules/contrib/experience_builder/ui/node_modules/.bin/cypress" # Check for the presence of Cypress. if ! command -v "$CYPRESS_BIN" &>/dev/null; then @@ -20,20 +21,40 @@ if ! command -v "$CYPRESS_BIN" &>/dev/null; then exit 1 fi -# Check if XQuartz is installed and running. -if ! open -Ra XQuartz; then - echo "Cannot find XQuartz. Install it and try again." - echo "Hint: https://github.com/TravisCarden/ddev-drupal-xb-dev#cypress" - exit 1 +# On Mac, check if XQuartz is installed and running. +if [[ "$OSTYPE" == "darwin"* ]]; then + if ! open -Ra XQuartz; then + echo "Cannot find XQuartz. Install it and try again." + echo "Hint: https://github.com/TravisCarden/ddev-drupal-xb-dev#cypress" + exit 1 + fi + + # Start XQuartz if it isn't running. + if ! pgrep -x Xquartz &>/dev/null; then + open -a XQuartz + # Give it a moment to start up. + sleep 2 + fi fi -# Start XQuartz if it isn't running. -if ! pgrep -x Xquartz &>/dev/null; then - open -a XQuartz - # Give it a moment to start up. - sleep 2 +# Running on WSL2 +if [[ "$OSTYPE" == "linux"* && ! -z "$WSL_DISTRO_NAME" ]]; then + # This assumes installation would be on C: and no custom path. + if [[ -f /mnt/c/Program\ Files/VcXsrv/vcxsrv.exe ]]; then + # Check if it's running, as you cannot have two instances + X_RUNNING=$(powershell.exe -Command "Get-Process vcxsrv" -ErrorAction SilentlyContinue) + if [[ -z $X_RUNNING ]]; then + powershell.exe -Command "Start-Process -FilePath 'C:\Program Files\VcXsrv\vcxsrv.exe' -ArgumentList '-multiwindow -ac -wgl'" + fi + else + echo "Cannot find VcXsrv. Install it and try again." + echo "Hint: https://github.com/TravisCarden/ddev-drupal-xb-dev#cypress" + exit 1 + fi fi +# Linux? You are on your own, but might _just_ work. + # Open up the allowed X11 hosts. xhost + @@ -41,7 +62,8 @@ xhost + function xb_cypress { ddev exec \ --dir /var/www/html/web/modules/contrib/experience_builder/ui \ - "$CYPRESS_BIN $1" + # This needs to be the binary path inside the container. + "$CYPRESS_BIN_INSIDE $1" } # Remove "--", if present, or it gets treated as the command argument. From 5f88a260f1780ad5abfcc7398268a4a260f8eee1 Mon Sep 17 00:00:00 2001 From: Christian Lopez Espinola Date: Wed, 12 Mar 2025 05:25:00 +0100 Subject: [PATCH 2/5] Fix faq. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6164d13..41eebd0 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,9 @@ ddev cypress component ### Can I use Cypress on Linux or Windows? -No, not currently; and there are no plans at present to support it. See [Support & community](#support--community) above if you want to make a case for it. +For Windows + WSL2, some people were able to use an X server successfully. See instructions for [Windows+WSL2](#setup-for-windows-using-ddev-inside-wsl2). +For Linux we don't have yet proof that it works. +See [Support & community](#support--community) above if you want to make a case for it. ### What if Cypress fails to start? From 03fb45c174910438d62ec06b7c797dd648dbb495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Esp=C3=ADnola?= Date: Sat, 15 Mar 2025 11:14:32 +0000 Subject: [PATCH 3/5] Fix comment. --- commands/host/xb-cypress | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/host/xb-cypress b/commands/host/xb-cypress index f1de883..51c9545 100755 --- a/commands/host/xb-cypress +++ b/commands/host/xb-cypress @@ -60,9 +60,9 @@ xhost + # Runs a given Cypress command, e.g., `xb_cypress run --e2e`. function xb_cypress { + # This needs to be the binary path inside the container. ddev exec \ --dir /var/www/html/web/modules/contrib/experience_builder/ui \ - # This needs to be the binary path inside the container. "$CYPRESS_BIN_INSIDE $1" } From 15ea46dfad00b622fb6e0c8ed9435776aee8f643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Esp=C3=ADnola?= Date: Tue, 8 Apr 2025 21:47:27 +0200 Subject: [PATCH 4/5] Use https://github.com/drupal-xb/ddev-drupal-xb-dev Co-authored-by: Travis Carden --- commands/host/xb-cypress | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/host/xb-cypress b/commands/host/xb-cypress index 51c9545..fc03a9e 100755 --- a/commands/host/xb-cypress +++ b/commands/host/xb-cypress @@ -25,7 +25,7 @@ fi if [[ "$OSTYPE" == "darwin"* ]]; then if ! open -Ra XQuartz; then echo "Cannot find XQuartz. Install it and try again." - echo "Hint: https://github.com/TravisCarden/ddev-drupal-xb-dev#cypress" + echo "Hint: https://github.com/drupal-xb/ddev-drupal-xb-dev#cypress" exit 1 fi @@ -48,7 +48,7 @@ if [[ "$OSTYPE" == "linux"* && ! -z "$WSL_DISTRO_NAME" ]]; then fi else echo "Cannot find VcXsrv. Install it and try again." - echo "Hint: https://github.com/TravisCarden/ddev-drupal-xb-dev#cypress" + echo "Hint: https://github.com/drupal-xb/ddev-drupal-xb-dev#cypress" exit 1 fi fi From 5574a905f95291a0a7e8b6666a1c8aef2c7e4d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=B3pez=20Esp=C3=ADnola?= Date: Tue, 8 Apr 2025 21:48:22 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Fix docs structure and warnings. Co-authored-by: Travis Carden --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 41eebd0..e79bf2a 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,9 @@ Update the Experience Builder module clone just like you would any other Git rep Experience Builder uses [Cypress](https://www.cypress.io/) for front-end testing. It is currently only supported on macOS. Linux and Windows with WSL2 might work with the instructions below. -### Setup for MacOS +### Setup + +#### macOS > Carefully follow the below XQuartz configuration steps after installing it. Failure to do so will result in frustrating, difficult to debug problems. @@ -109,9 +111,9 @@ Configure XQuartz to allow connections from the host: ![XQuartz Preferences dialog](resources/xquartz-settings.png) -### Setup for Windows using ddev inside WSL2 +#### Windows -> This is experimental. +> **Note:** This is experimental and officially unsupported. Members of the community who use Windows may be able to provide unofficial support. See [Support \& community](#support--community). Be sure to thank them. They're giving up their personal time to help you. Install [VcXsrv Windows X Server](https://sourceforge.net/projects/vcxsrv) in the default "C:/Program Files" location. You might need to restart your system afterwards. @@ -144,11 +146,9 @@ ddev cypress component ## FAQ & known issues -### Can I use Cypress on Linux or Windows? +### Can I use Cypress on Windows or Linux? -For Windows + WSL2, some people were able to use an X server successfully. See instructions for [Windows+WSL2](#setup-for-windows-using-ddev-inside-wsl2). -For Linux we don't have yet proof that it works. -See [Support & community](#support--community) above if you want to make a case for it. +Windows and Linux are not officially supported, however, some people have reported it working on Windows + WSL2. See [Windows setup](#windows). We have no reports of anyone trying to use it on Linux. By all means, see [Support & community](#support--community) to share your experience if you have. ### What if Cypress fails to start?