From 0e65fb67feb8c36ae18178a798003ecadba1c95a Mon Sep 17 00:00:00 2001 From: Sine Jespersen Date: Fri, 1 Aug 2025 13:15:11 +0200 Subject: [PATCH 1/2] 4565: bash script argument and error handling --- scripts/test | 24 ++++++++++++++++++++++++ scripts/test.sh | 8 -------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100755 scripts/test delete mode 100755 scripts/test.sh diff --git a/scripts/test b/scripts/test new file mode 100755 index 00000000..ed98d4a3 --- /dev/null +++ b/scripts/test @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# -o errexit: Exit immediately if a command exits with a non-zero status. +# -o errtrace: Ensures that the ERR trap is also triggered when the error occurs inside a function or a subshell. (https://stackoverflow.com/questions/25378845/what-does-set-o-errtrace-do-in-a-shell-script) +# -o noclobber: Prevents accidentally overwriting files with output redirection. +# -o nounset: This command will cause the shell to exit if a variable is accessed before it is set. +# -o pipefail: Ensures that a pipeline return the exit status of the command that first fails. +set -o errexit -o errtrace -o noclobber -o nounset -o pipefail + +TEST_PATH="${1:-}" + +# Stop node container to avoid build conflicts. +docker compose stop node +# Build assets. +docker compose run --rm node npm run build + +# Run tests (with or without a test path) +if [[ -n "$TEST_PATH" ]]; then + docker compose run --rm playwright npx playwright test "$TEST_PATH" +else + docker compose run --rm playwright npx playwright test +fi +# Restart node container. +docker compose start node diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index aa6cdc02..00000000 --- a/scripts/test.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Stop node container to avoid build conflicts. -docker compose stop node -# Build assets. -docker compose run --rm node npm run build -# Run tests. -docker compose run --rm playwright npx playwright test ${TEMPLATE_FILTER} -# Restart node container. -docker compose start node From 70aca235020c177366192b016551c1119970335b Mon Sep 17 00:00:00 2001 From: Sine Jespersen Date: Fri, 1 Aug 2025 13:15:22 +0200 Subject: [PATCH 2/2] 4565: documentation of test script added --- docs/test.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/test.md b/docs/test.md index 1fb947d9..d0ed9808 100644 --- a/docs/test.md +++ b/docs/test.md @@ -12,6 +12,18 @@ See the `docker-compose.override.yml` playwright entry and the version imported ### Dev mode +This project includes a test script that handles building assets, running +Playwright tests, and stops and starts the node container. This script tests the +*built* files. + +```bash +./scripts/test {TEST-PATH} +``` + +TEST-PATH is optional, and is the specific test file or directory to run like +`admin`/`client`/`template` or a specific file, e.g. `admin-app.spec.js`. If +TEST-PATH is omitted, all tests will run. + To run tests locally, there are a few options. To run from the developer machine: