Skip to content

Instructions and commands for running cypress on Windows+WSL2 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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,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/.
Expand All @@ -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:
Expand Down Expand Up @@ -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?

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