-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·88 lines (77 loc) · 3.15 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·88 lines (77 loc) · 3.15 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
#!/usr/bin/env bash
#
# run-tests.sh — run the project's test suites and print the results.
#
# Usage:
# ./run-tests.sh # lint + unit (vitest) + e2e (playwright)
# ./run-tests.sh unit # unit tests only
# ./run-tests.sh e2e # e2e tests only
# ./run-tests.sh lint # lint only
# ./run-tests.sh --update-snapshots # pass extra args through to playwright
#
# Exits non-zero if any selected suite fails.
set -uo pipefail
cd "$(dirname "$0")"
# --- pretty output ---------------------------------------------------------
if [ -t 1 ]; then
BOLD=$(printf '\033[1m'); GREEN=$(printf '\033[32m'); RED=$(printf '\033[31m')
YELLOW=$(printf '\033[33m'); DIM=$(printf '\033[2m'); RESET=$(printf '\033[0m')
else
BOLD=""; GREEN=""; RED=""; YELLOW=""; DIM=""; RESET=""
fi
section() { printf '\n%s========== %s ==========%s\n' "$BOLD" "$1" "$RESET"; }
# --- parse args ------------------------------------------------------------
# A bare "unit" / "e2e" / "lint" selects a single suite; anything else (e.g.
# --update-snapshots) is forwarded to the playwright invocation.
SUITE="all"
PW_ARGS=()
for arg in "$@"; do
case "$arg" in
unit|e2e|lint) SUITE="$arg" ;;
*) PW_ARGS+=("$arg") ;;
esac
done
run_lint=false; run_unit=false; run_e2e=false
case "$SUITE" in
all) run_lint=true; run_unit=true; run_e2e=true ;;
lint) run_lint=true ;;
unit) run_unit=true ;;
e2e) run_e2e=true ;;
esac
lint_status="skipped"; unit_status="skipped"; e2e_status="skipped"
# --- lint ------------------------------------------------------------------
if $run_lint; then
section "Lint (eslint)"
# Lint the entire codebase, but skip the two stylistic rules the app source
# hasn't been migrated to yet (semicolons + trailing commas). These stay
# enforced in the editor / `npm run lint`; we only relax them here.
if npx eslint . \
--rule '@stylistic/semi: off' \
--rule '@stylistic/comma-dangle: off'; then
lint_status="${GREEN}passed${RESET}"
else
lint_status="${RED}failed${RESET}"
fi
fi
# --- unit ------------------------------------------------------------------
if $run_unit; then
section "Unit tests (vitest)"
if npx vitest run; then unit_status="${GREEN}passed${RESET}"; else unit_status="${RED}failed${RESET}"; fi
fi
# --- e2e -------------------------------------------------------------------
if $run_e2e; then
section "E2E tests (playwright)"
printf '%sStarts a dev server and runs browser tests; this can take a few minutes.%s\n' "$DIM" "$RESET"
if npx playwright test ${PW_ARGS[@]+"${PW_ARGS[@]}"}; then e2e_status="${GREEN}passed${RESET}"; else e2e_status="${RED}failed${RESET}"; fi
fi
# --- summary ---------------------------------------------------------------
section "Summary"
printf ' %-26s %b\n' "Lint (eslint)" "$lint_status"
printf ' %-26s %b\n' "Unit tests (vitest)" "$unit_status"
printf ' %-26s %b\n' "E2E tests (playwright)" "$e2e_status"
printf '%sTip: the e2e suite intentionally has failing tests that document spec/code divergences.%s\n' "$DIM" "$RESET"
# Exit non-zero if any selected suite failed.
if printf '%s%s%s' "$lint_status" "$unit_status" "$e2e_status" | grep -q "failed"; then
exit 1
fi
exit 0