Skip to content

Commit

Permalink
Initial setup (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
deviantintegral authored May 3, 2023
2 parents c2eef05 + a881296 commit abfff69
Show file tree
Hide file tree
Showing 26 changed files with 691 additions and 115 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ jobs:
uses: Homebrew/actions/setup-homebrew@master
- name: Environment setup
run: |
brew install bats-core mkcert
brew install mkcert
mkcert -install
git submodule init
git submodule update
- name: Use ddev stable
if: matrix.ddev_version == 'stable'
Expand Down Expand Up @@ -80,9 +82,9 @@ jobs:
if: github.event.inputs.debug_enabled == 'true'

- name: tests
run: bats tests
run: ./tests/bats/bin/bats tests

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
- uses: gautamkrishnar/keepalive-workflow@v1
if: matrix.ddev_version == 'stable'
if: matrix.ddev_version == 'stable'
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "tests/bats"]
path = tests/bats
url = https://github.com/bats-core/bats-core.git
[submodule "tests/test_helper/bats-support"]
path = tests/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "tests/test_helper/bats-assert"]
path = tests/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
26 changes: 26 additions & 0 deletions commands/host/install-playwright
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#ddev-generated

mkdir -p test/playwright
if [ ! -f test/playwright/package.json ]; then
echo "No playwright installation exists at test/playwright."
# https://github.com/microsoft/playwright/issues/11843
echo "Playwright does not support a non-interactive setup and must be done manually."
echo ""
echo "Run the following to use npm:"
echo ddev exec -d /var/www/html/test/playwright npm init playwright@latest
echo ""
echo "Run the following to use yarn instead:"
echo ddev exec -d /var/www/html/test/playwright yarn create playwright
echo ""
echo "See https://playwright.dev/docs/intro for more details."
echo ""
echo "When done, run: ddev install-playwright"
exit 1
fi

# ddev errors out on subsequent builds if we symlink these files. Instead, we
# copy them each time.
echo "Rebuilding web service with playwright dependencies..."
cp .ddev/web-build/disabled.Dockerfile.playwright .ddev/web-build/Dockerfile.playwright
ddev restart
10 changes: 10 additions & 0 deletions commands/web/playwright
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
#ddev-generated

cd test/playwright

if [ -f yarn.lock ]; then
yarn && yarn playwright "$@"
else
npx playwright "$@"
fi
35 changes: 35 additions & 0 deletions config.playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ddev-generated
hooks:
pre-start:
# If Playwright is enabled, make sure we get any changes.
- exec-host: |
([[ -f .ddev/web-build/Dockerfile.playwright ]] && \
cp .ddev/web-build/disabled.Dockerfile.playwright .ddev/web-build/Dockerfile.playwright) || true
- exec-host: |
if [[ -f .ddev/web-build/Dockerfile.playwright ]]
then
rm -rf .ddev/web-build/playwright
cp -r test/playwright .ddev/web-build/
fi
web_environment:
- DISPLAY=:99.0
# We add the sleep so this doesn't error out when not using playwright.
web_extra_daemons:
- name: "xvfb"
command: "/usr/local/bin/start-xvfb.sh || sleep infinity"
directory: /var/www/html
- name: "vnc"
command: "/usr/local/bin/start-vnc.sh || sleep infinity"
directory: /var/www/html
- name: "novnc"
command: "/usr/local/bin/start-novnc.sh || sleep infinity"
directory: /var/www/html
web_extra_exposed_ports:
- name: playwright
container_port: 9323
http_port: 8323
https_port: 9324
- name: novnc
container_port: 7900
http_port: 7910
https_port: 7900
16 changes: 0 additions & 16 deletions docker-compose.addon-template.yaml

This file was deleted.

79 changes: 4 additions & 75 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -1,81 +1,10 @@
name: addon-template

# pre_install_actions - list of actions to run before installing the addon.
# Examples would be removing an extraneous docker volume,
# or doing a sanity check for requirements.
# DDEV environment variables can be interpolated into these actions
pre_install_actions:
# Actions with #ddev-nodisplay will not show the execution of the action, but may show their output
# - |
# #ddev-nodisplay
#ddev-description:Check architecture type for incompatible arm64 type
# if [ "$(arch)" = "arm64" -o "$(arch)" = "aarch64" ]; then
# echo "This package does not work on arm64 machines";
# exit 1;
#fi

# - "docker volume rm ddev-${DDEV_PROJECT}_solr 2>/dev/null || true"
#- |
# # Using #ddev-nodisplay tells ddev to be quiet about this action and not show it or its output.
# #ddev-nodisplay
# #ddev-description:Remove solr volume
# if ! ( ddev debug capabilities 2>/dev/null | grep multiple-dockerfiles >/dev/null 2>&1 ) ; then
# echo "This add-on requires DDEV v1.19.4 or higher, please upgrade." && exit 2
# fi
#- 'echo "what is your platform.sh token" && read x'

# This item shows templating using DDEV environment variables.
# -
# #ddev-description:Touch a file to create it
# touch somefile.${DDEV_PROJECT_TYPE}.${DDEV_DOCROOT}.txt
#

# This item shows complex go templating possibilities based on yaml_read_files
#- |
#- #ddev-description:Create a config.platformsh.yaml
# cat <<EOF >.ddev/config.platformsh.yaml
# php_version: {{ trimPrefix "php:" .platformapp.type }}
# database:
# type: {{ regexReplaceAll ":.*$" .services.db.type "" }}
# version: {{ regexReplaceAll "^.*:" .services.db.type "" }}
#
# docroot: {{ dig "web" "locations" "/" "root" "notfound" .platformapp }}
# {{ if eq .platformapp.build.flavor "composer" }}
# hooks:
# post-start:
# - composer: install
# {{ if .platformapp.hooks.deploy }}
# - exec: "{{ trimAll "\n" .platformapp.hooks.deploy | splitList "\n" | join ` && ` }}"
# {{ end }}
# {{ end }}
#
# EOF
name: ddev-playwright

# list of files and directories listed that are copied into project .ddev directory
# Each file should contain #ddev-generated so it can be replaced by a later `ddev get`
# if it hasn't been modified by the user.
# DDEV environment variables can be interpolated into these filenames
project_files:
- docker-compose.addon-template.yaml
# - extra_files/
# - somefile.sh

# List of files and directories that are copied into the global .ddev directory
# DDEV environment variables can be interpolated into these filenames
global_files:
# - commands
# - homeadditions

# DDEV environment variables can be interpolated into these actions
post_install_actions:
# - chmod +x ~/.ddev/commands/web/somecommand
# - touch somefile.${GOOS}.${DDEV_WEBSERVER}
# - perl -pi -e 's/oldstring/newstring/g' docker-compose.addon-template.yaml

# Advanced usage - yaml files can be read in and then used as go template actions
# in pre_install_actions and post_install_actions
# See example in
# https://github.com/rfay/ddev/blob/20220606_yaml_read_experiment/cmd/ddev/cmd/testdata/TestCmdGetComplex/recipe/install.yaml
yaml_read_files:
# someyaml: someyaml.yaml
# otheryaml: someotheryaml.yaml
- commands/
- web-build/
- config.playwright.yml
1 change: 1 addition & 0 deletions tests/bats
Submodule bats added at 4417a9
135 changes: 114 additions & 21 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,44 +1,137 @@
setup_file() {
# Clean up any stale locks from previous test runs.
export GLOBAL_DDEV_LOCK=~/tmp/test-addon-ddev-playwright.lock
release_global_ddev
}

setup() {
set -eu -o pipefail
export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/test-addon-template
mkdir -p $TESTDIR
export PROJNAME=test-addon-template
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
export DIR
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."

# This was written so we could use bats' --jobs parameter to support multiple
# parallel tests. Unfortunately, running in parallel causes ddev state to
# become corrupt. I think these are ddev bugs. Since I figured out the temp
# handling already, I've added locks around the commands that potentially have
# global affects.

# We need to override /tmp because that is not mounted by default in macOS
# Docker software like Colima and Docker Desktop.
# https://stackoverflow.com/questions/31396985/why-is-mktemp-on-os-x-broken-with-a-command-that-worked-on-linux
mkdir -p ~/tmp

# Clean up any stale locks from previous test runs.
export GLOBAL_DDEV_LOCK=~/tmp/test-addon-ddev-playwright.lock
release_global_ddev

export TESTDIR
TESTDIR=$(mktemp -d "${HOME}/tmp/test-addon-ddev-playwright.XXXXXXXXX")

export PROJNAME=test-addon-ddev-playwright-${BATS_SUITE_TEST_NUMBER}
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1 || true

wait_for_global_ddev
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1 || true
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME}
mkdir -p web
ddev config --project-name="${PROJNAME}" --docroot=web --project-type=php
echo "# ddev start" >&3
ddev start -y >/dev/null
release_global_ddev
}

wait_for_global_ddev() {
while ! (set -o noclobber ; echo > "$GLOBAL_DDEV_LOCK"); do
sleep 1
done
}

release_global_ddev() {
rm -f "$GLOBAL_DDEV_LOCK"
}

health_checks() {
# Do something useful here that verifies the add-on
# ddev exec "curl -s elasticsearch:9200" | grep "${PROJNAME}-elasticsearch"
ddev exec "curl -s https://localhost:443/"
ddev exec "curl -s https://localhost:443/ | grep -q phpinfo"
}

teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME} >/dev/null 2>&1
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
cd "${TESTDIR}" || ( printf "unable to cd to %s\n" "${TESTDIR}" && exit 1 )
wait_for_global_ddev
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1
release_global_ddev
[ "${TESTDIR}" != "" ] && rm -rf "${TESTDIR}"
}

@test "install from directory" {
get_addon() {
set -eu -o pipefail
cd ${TESTDIR}
cd "${TESTDIR}"
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR}
ddev restart
ddev get "${DIR}"
assert [ -f .ddev/config.playwright.yml ]
assert [ -f .ddev/commands/host/install-playwright ]
assert [ -f .ddev/commands/web/playwright ]
assert [ -f .ddev/web-build/.gitignore ]
assert [ -f .ddev/web-build/disabled.Dockerfile.playwright ]
assert [ -f .ddev/web-build/start-novnc.sh ]
assert [ -f .ddev/web-build/start-vnc.sh ]
assert [ -f .ddev/web-build/start-xvfb.sh ]
mkdir test
}

verify_run_playwright() {
cp -av "$DIR"/tests/testdata/web/* web/
assert [ -f web/index.php ]
ddev install-playwright
mkdir -p test/playwright/tests
cp "$DIR"/tests/testdata/phpinfo.spec.ts test/playwright/tests/phpinfo.spec.ts
health_checks

# Verify noVNC is listening.
curl -s https://"${PROJNAME}".ddev.site:7900/

# Verify that browsers have been downloaded.
ddev exec -- ls \~/.cache/ms-playwright
run ddev exec -- ls \~/.cache/ms-playwright \| wc -l \| sed \'s/ *//\'
# Playwright currently supports 4 browsers.
assert_output 4

# Verify we can run an example test.
ddev playwright test --reporter=line
}

@test "install from directory with npm" {
get_addon
cp -av "$DIR"/tests/testdata/npm-playwright test/playwright
ddev exec -d /var/www/html/test/playwright npm ci
verify_run_playwright
}

@test "install from directory with yarn" {
get_addon
cp -av "$DIR"/tests/testdata/yarn-playwright test/playwright
verify_run_playwright
}

@test "install from release" {
@test "install requires a playwright installation" {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get ddev/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ddev/ddev-addon-template
ddev restart >/dev/null
health_checks
cd "${TESTDIR}"
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get "${DIR}"
run ddev install-playwright
assert_failure
}

#@test "install from release" {
# set -eu -o pipefail
# cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
# echo "# ddev get ddev/ddev-addon-template with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
# ddev get ddev/ddev-addon-template
# ddev restart >/dev/null
# health_checks
#}
#
#
1 change: 1 addition & 0 deletions tests/test_helper/bats-assert
Submodule bats-assert added at 44913f
1 change: 1 addition & 0 deletions tests/test_helper/bats-support
Submodule bats-support added at 3c8fad
4 changes: 4 additions & 0 deletions tests/testdata/npm-playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
Loading

0 comments on commit abfff69

Please sign in to comment.