Skip to content

Instantly share code, notes, and snippets.

@mikeshiyan
Last active December 19, 2023 13:33
Show Gist options
  • Save mikeshiyan/a91b6aadcf76734dfad08dd5811119de to your computer and use it in GitHub Desktop.
Save mikeshiyan/a91b6aadcf76734dfad08dd5811119de to your computer and use it in GitHub Desktop.
Landofile for running PHPUnit and Nightwatch JS tests in a local Drupal repo (any branch).
name: drupal-test
recipe: drupal9
config:
webroot: .
php: 8.1
services:
appserver:
build_as_root:
# Install nodejs and yarn in the main container. They have to live here
# because PHP is required for the site installation and other ops in
# nightwatch tests.
# Following lines don't contain anything specific to Lando. Change them
# only according to the official docs of nodejs and yarn.
- curl -sL https://deb.nodesource.com/setup_16.x | bash -
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt-get update > /dev/null && apt-get install -y build-essential nodejs yarn
build:
- mkdir -p ${LANDO_WEBROOT}/sites/simpletest/browser_output
- cd ${LANDO_WEBROOT}/core && yarn install
overrides:
environment:
# These env vars can be placed in the web/core/.env file, which can be
# lost on core updates. So they are here instead. Their docs are in
# web/core/.env.example file.
# Replace the project name in the base url.
# The DB url needs to point to an existing DB, tests will create and
# drop prefixed tables in it.
# Change the nightwatch output dir if needed.
# `lando rebuild` after changes.
DRUPAL_TEST_BASE_URL: https://drupal-test.lndo.site
DRUPAL_TEST_DB_URL: mysql://drupal9:drupal9@database/drupal9
DRUPAL_TEST_WEBDRIVER_HOSTNAME: chromedriver
DRUPAL_TEST_WEBDRIVER_PORT: 9515
DRUPAL_TEST_CHROMEDRIVER_AUTOSTART: 'false'
DRUPAL_TEST_WEBDRIVER_CHROME_ARGS: --disable-gpu --headless --no-sandbox
DRUPAL_NIGHTWATCH_OUTPUT: ../sites/nightwatch
DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES: node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest
# PhpUnit vars.
SIMPLETEST_BASE_URL: https://drupal-test.lndo.site
SIMPLETEST_DB: mysql://drupal9:drupal9@database/drupal9
BROWSERTEST_OUTPUT_DIRECTORY: /app/sites/simpletest/browser_output
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", { "chromeOptions": { "args": [ "disable-gpu", "headless", "no-sandbox" ] } }, "http://chromedriver:9515"]'
chromedriver:
type: compose
services:
image: drupalci/chromedriver:production
# This is the ENTRYPOINT + CMD from the Dockerfile. Empty whitelisted-ips
# param opens the chromedriver port for other hosts.
command: chromedriver --log-path=/tmp/chromedriver.log --verbose --whitelisted-ips=
tooling:
drush:
service: appserver
env:
DRUSH_OPTIONS_URI: "https://drupal-test.lndo.site"
nightwatch:
service: appserver
cmd: cd ${LANDO_WEBROOT}/core && yarn test:nightwatch
phpunit:
service: appserver
cmd: phpunit -c /app/core/phpunit.xml.dist --bootstrap /app/core/tests/bootstrap.php --printer "\Drupal\Tests\Listeners\HtmlOutputPrinter"

POC

First clone Drupal core and install dependencies:

git clone https://git.drupalcode.org/project/drupal.git .
composer i

Then copy this landofile to the project root and change as needed. Start lando.

wget https://gist.githubusercontent.com/mikeshiyan/a91b6aadcf76734dfad08dd5811119de/raw/.lando.yml
lando start

Finally run tests. E.g.:

lando phpunit modules/contrib/
lando nightwatch /app/modules/contrib/
@mikeshiyan
Copy link
Author

mikeshiyan commented Nov 21, 2023

This needs an update - nightwatch stopped working for some reason.
Also this node setup is deprecated.

@mikeshiyan
Copy link
Author

A fresh working example (for a specific drupal contrib project) is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment