Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down Expand Up @@ -138,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?

Expand Down
46 changes: 34 additions & 12 deletions commands/host/xb-cypress
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,63 @@
## 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
echo "Cypress is not installed. Run 'ddev xb-ui-build' and try again."
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like someone with experience with WSL2 to review this.

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 +

# 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.
Expand Down