Skip to content

Commit

Permalink
Add Nightwatch support
Browse files Browse the repository at this point in the history
  • Loading branch information
justafish committed Oct 19, 2023
1 parent 699ad98 commit ae42a50
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cd drupal
ddev config --auto
ddev get justafish/ddev-drupal-core-dev
ddev start
ddev composer install
# See included commands
ddev drupal list
Expand All @@ -17,4 +18,48 @@ ddev drupal install
# Run PHPUnit tests
ddev phpunit core/modules/sdc
# Run Nightwatch tests (currently only runs on Chrome)
ddev nightwatch --tag core
```

## Nightwatch Examples
Only core tests
```
ddev nightwatch --tag core
```

Skip running core tests
```
ddev nightwatch --skiptags core
```

Run a single test
```
ddev nightwatch tests/Drupal/Nightwatch/Tests/exampleTest.js
```

a11y tests for both the admin and default themes
```
ddev nightwatch --tag a11y
```

a11y tests for the admin theme only
```
ddev nightwatch --tag a11y:admin
```

a11y tests for the default theme only
```
ddev nightwatch --tag a11y:default
```

a11y test for a custom theme used as the default theme
```
ddev nightwatch --tag a11y:default --defaultTheme bartik
```

a11y test for a custom admin theme
```
ddev nightwatch --tag a11y:admin --adminTheme seven
```
10 changes: 10 additions & 0 deletions commands/host/nightwatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

#ddev-generated
## Description: Run Nightwatch
## Usage: nightwatch
## Example: "ddev nightwatch --tag core"

echo "Restarting Chrome container"
docker container restart ddev-$DDEV_PROJECT-chrome
ddev _nightwatch "$@"
8 changes: 8 additions & 0 deletions commands/web/_nightwatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

#ddev-generated
## Description: Pass through command for Nightwatch, use ddev nightwatch instead
## Usage: _nightwatch
## Example: "Don't use this"

cd core && yarn test:nightwatch "$@"
82 changes: 82 additions & 0 deletions core-dev/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#ddev-generated
# This is a dotenv file used by JavaScript tasks.
# Copy this to '.env' to override.

#############################
# General Test Environment #
#############################
# This is the URL that Drupal can be accessed by. You don't need an installed
# site here, just make sure you can at least access the installer screen. If you
# don't already have one running, e.g. Apache, you can use PHP's built-in web
# server by running the following command in your Drupal root folder:
# php -S localhost:8888 .ht.router.php
# DRUPAL_TEST_BASE_URL=http://localhost:8888
DRUPAL_TEST_BASE_URL=http://web

# Tests need to be executed with a user in the same group as the web server
# user.
#DRUPAL_TEST_WEBSERVER_USER=www-data

# By default we use sqlite as database. Use
# mysql://username:password@localhost/databasename#table_prefix for mysql.
DRUPAL_TEST_DB_URL=sqlite://localhost/sites/default/files/db.sqlite

#############
# Webdriver #
#############

# If Chromedriver is running as a service elsewhere, set it here.
# When using DRUPAL_TEST_CHROMEDRIVER_AUTOSTART leave this at the default settings.
DRUPAL_TEST_WEBDRIVER_HOSTNAME=chrome
DRUPAL_TEST_WEBDRIVER_PORT=4444

# If using Selenium, override the path prefix here.
# See http://nightwatchjs.org/gettingstarted#browser-drivers-setup
#DRUPAL_TEST_WEBDRIVER_PATH_PREFIX=/wd/hub

################
# Chromedriver #
################

# Automatically start chromedriver for local development. Set to false when you
# use your own webdriver or chromedriver setup.
# Also set it to false when you use a different browser for testing.
DRUPAL_TEST_CHROMEDRIVER_AUTOSTART=false

# A list of arguments to pass to Chrome, separated by spaces
# e.g. `--disable-gpu --headless --no-sandbox`.
#DRUPAL_TEST_WEBDRIVER_CHROME_ARGS=

# A list of arguments to pass to Webdriver, separated by spaces
# e.g. `--allowed-ips --disable-dev-shm-usage`.
#DRUPAL_TEST_WEBDRIVER_CLI_ARGS=

##############
# Nightwatch #
##############

# Nightwatch generates output files. Use this to specify the location where these
# files need to be stored. The default location is ignored by git, if you modify
# the location you will probably want to add this location to your .gitignore.
DRUPAL_NIGHTWATCH_OUTPUT=test_output/nightwatch

# The path that Nightwatch searches for assumes the same directory structure as
# when you download Drupal core. If you have Drupal installed into a docroot
# folder, you can use the following folder structure to add integration tests
# for your project, outside of tests specifically for custom modules/themes/profiles.
#
# .
# ├── docroot
# │ ├── core
# ├── tests
# │ ├── Nightwatch
# │ │ ├── Tests
# │ │ │ ├── myTest.js
#
# and then set DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY=../
#
#DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY=

# Filter directories to look for tests. This uses minimatch syntax.
# Separate folders with a comma.
DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES=node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest
12 changes: 12 additions & 0 deletions install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
name: ddev-drupal-core-dev

project_files:
- web-build/Dockerfile
- docker-compose.core-dev-selenium.yaml
- core-dev/phpunit-firefox.xml
- core-dev/phpunit-chrome.xml
- commands/web/drupal
- commands/web/phpunit
- commands/host/nightwatch
- commands/web/_nightwatch
- core-dev/gitignore
- core-dev/.env
- core-dev/src/Command/AdminLoginCommand.php
- core-dev/src/Command/BootCommand.php
- core-dev/src/Command/CacheCommand.php
Expand All @@ -31,6 +35,12 @@ post_install_actions:
if ! grep -q "\/\.ddev" ../.git/info/exclude; then
echo "/.ddev" >> ../.git/info/exclude
fi
- |
if ! grep -q "\/sites\/sites.php" ../.git/info/exclude; then
echo "/sites/sites.php" >> ../.git/info/exclude
fi
- cp core-dev/.env ../core/.env
- cd ../core && yarn install

removal_actions:
- rm core/phpunit.xml
Expand All @@ -40,3 +50,5 @@ removal_actions:
- rm -f sites/default/files/.gitignore
- sed '/\/sites\/default\/settings\.php/d' -i .git/info/exclude
- sed '/\/\.ddev/d' -i .git/info/exclude
- sed '/\/sites\/sites\.php/d' -i .git/info/exclude
- rm core/.env
2 changes: 2 additions & 0 deletions web-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#ddev-generated
RUN sudo apt-get update && sudo apt-get install chromium-driver -y

0 comments on commit ae42a50

Please sign in to comment.