-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathrun-e2e-tests
executable file
·93 lines (83 loc) · 2.59 KB
/
run-e2e-tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
# Run end-to-end tests of UI navigation.
# Exit on unset variable.
set -u
# Exit on first failure.
set -e
print_help() {
cat << EOF
Usage: ${0##*/} [--help] [--base-url E2E_BASE_URL] [-- [PLAYWRIGHT_ARGS]]
Run end-to-end tests of UI navigation.
--help Optional. Display this help and exit.
--base-url E2E_BASE_URL Optional. The base URL of the running TinyPilot server
to test against. Must start with 'http'. If not
specified, the script will start a local dev server.
-- PLAYWRIGHT_ARGS Optional. Indicate the end of this script's CLI
options and add Playwright CLI test options.
See https://playwright.dev/docs/test-cli#reference
For example:
run-e2e-tests -- --grep 'shows privacy policy'
EOF
}
# Parse command-line arguments.
E2E_BASE_URL=''
PLAYWRIGHT_ARGS=()
while (( "$#" > 0 )); do
case "$1" in
--help)
print_help
exit
;;
--base-url)
if (( "$#" < 2 )); then
shift;
break;
fi
E2E_BASE_URL="$2"
shift # For flag name.
shift # For flag value.
;;
--)
# Stop parsing command-line arguments, and capture all remaining
# args to pass them through to Playwright.
shift
PLAYWRIGHT_ARGS=("$@")
break
;;
*)
>&2 echo "Unknown flag: $1"
>&2 print_help
exit 1
;;
esac
done
readonly E2E_BASE_URL
readonly PLAYWRIGHT_ARGS
if [[ -n "${E2E_BASE_URL}" && ! "${E2E_BASE_URL[0]}" =~ ^http ]]; then
>&2 echo "Invalid base URL: ${E2E_BASE_URL}"
>&2 echo 'The base URL must start with "http"'
>&2 print_help
exit 1
fi
# Echo commands before executing them, by default to stderr.
set -x
# Change directory to repository root.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."
if [[ -n "${E2E_BASE_URL}" ]]; then
# Indicate to playwright.config.js to override the default base URL and not to
# start a local webserver.
export E2E_BASE_URL
else
# When running against a local dev server, use a fresh home directory on each
# test run so that database state in one run doesn't affect subsequent runs.
TINYPILOT_HOME_DIR="$(mktemp --directory)"
export TINYPILOT_HOME_DIR
readonly TINYPILOT_HOME_DIR
fi
# To avoid an "unbound variable" error, we only expand the PLAYWRIGHT_ARGS when
# the array is not empty.
# https://stackoverflow.com/a/7577209/3769045
npx playwright test "${PLAYWRIGHT_ARGS[@]+"${PLAYWRIGHT_ARGS[@]}"}"