generated from ddev/ddev-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
691 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
#} | ||
# | ||
# |
Submodule bats-assert
added at
44913f
Submodule bats-support
added at
3c8fad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
Oops, something went wrong.