diff --git a/README.md b/README.md index 2f05ef8..dce274e 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,12 @@ 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 +#### macOS + > Carefully follow the below XQuartz configuration steps after installing it. Failure to do so will result in frustrating, difficult to debug problems. Install XQuartz using Homebrew. See also https://www.xquartz.org/. @@ -108,6 +111,13 @@ Configure XQuartz to allow connections from the host: ![XQuartz Preferences dialog](resources/xquartz-settings.png) +#### Windows + +> **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. + ### Usage Run Cypress tests interactively: @@ -136,9 +146,9 @@ ddev cypress component ## FAQ & known issues -### Can I use Cypress on Linux or Windows? +### Can I use Cypress on Windows or Linux? -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. +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? diff --git a/commands/host/xb-cypress b/commands/host/xb-cypress index a6f435d..fc03a9e 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,28 +21,49 @@ 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/drupal-xb/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/drupal-xb/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/drupal-xb/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 + # 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 \ - "$CYPRESS_BIN $1" + "$CYPRESS_BIN_INSIDE $1" } # Remove "--", if present, or it gets treated as the command argument.