-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.bats
More file actions
94 lines (81 loc) · 2.91 KB
/
Copy pathtest.bats
File metadata and controls
94 lines (81 loc) · 2.91 KB
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
94
#!/usr/bin/env bats
# Bats is a testing framework for Bash
# Documentation https://bats-core.readthedocs.io/en/stable/
# Bats libraries documentation https://github.com/ztombol/bats-docs
# For local tests, install bats-core, bats-assert, bats-file, bats-support
# And run this in the add-on root directory:
# bats ./tests/test.bats
# To exclude release tests:
# bats ./tests/test.bats --filter-tags '!release'
# For debugging:
# bats ./tests/test.bats --show-output-of-passing-tests --verbose-run --print-output-on-failure
setup() {
set -eu -o pipefail
export GITHUB_REPO=Metadrop/ddev-playwright
TEST_BREW_PREFIX="$(brew --prefix 2>/dev/null || true)"
export BATS_LIB_PATH="${BATS_LIB_PATH}:${TEST_BREW_PREFIX}/lib:/usr/lib/bats"
bats_load_library bats-assert
bats_load_library bats-file
bats_load_library bats-support
export DIR="$(cd "$(dirname "${BATS_TEST_FILENAME}")/.." >/dev/null 2>&1 && pwd)"
export PROJNAME="test-$(basename "${GITHUB_REPO}")"
mkdir -p "${HOME}/tmp"
export TESTDIR="$(mktemp -d "${HOME}/tmp/${PROJNAME}.XXXXXX")"
export DDEV_NONINTERACTIVE=true
export DDEV_NO_INSTRUMENTATION=true
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1 || true
cd "${TESTDIR}"
run ddev config --project-name="${PROJNAME}" --project-tld=ddev.site
assert_success
run ddev start -y
assert_success
}
health_checks() {
# Browsers are baked into the web image at build time
run ddev exec "npx playwright --version"
assert_success
assert_output --partial "Version"
run ddev exec "ls \$PLAYWRIGHT_BROWSERS_PATH"
assert_success
assert_output --partial "chromium"
assert_output --partial "firefox"
# Custom commands were installed
run ddev help
assert_output --partial "playwright"
assert_output --partial "playwright-report"
assert_output --partial "playwright-update-snapshots"
assert_output --partial "playwright-a11y-summary"
# The HTML report port is exposed via the router
run ddev describe
assert_output --partial "9323"
}
teardown() {
set -eu -o pipefail
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1
# Persist TESTDIR if running inside GitHub Actions. Useful for uploading test result artifacts
# See example at https://github.com/ddev/github-action-add-on-test#preserving-artifacts
if [ -n "${GITHUB_ENV:-}" ]; then
[ -e "${GITHUB_ENV:-}" ] && echo "TESTDIR=${HOME}/tmp/${PROJNAME}" >> "${GITHUB_ENV}"
else
[ "${TESTDIR}" != "" ] && rm -rf "${TESTDIR}"
fi
}
@test "install from directory" {
set -eu -o pipefail
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
run ddev add-on get "${DIR}"
assert_success
run ddev restart -y
assert_success
health_checks
}
# bats test_tags=release
@test "install from release" {
set -eu -o pipefail
echo "# ddev add-on get ${GITHUB_REPO} with project ${PROJNAME} in $(pwd)" >&3
run ddev add-on get "${GITHUB_REPO}"
assert_success
run ddev restart -y
assert_success
health_checks
}