|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -u |
| 3 | + |
| 4 | +# End-to-end web smoke test for the Loreline Godot integration. |
| 5 | +# |
| 6 | +# Patches the sample project's main_scene to the test_web_runner scene, |
| 7 | +# exports a Web build, serves it locally, runs headless Chromium via |
| 8 | +# Playwright and asserts the ALL_WEB_TESTS_PASSED marker, then restores |
| 9 | +# the original main_scene. Used by CI and by local developers (Mac+Linux). |
| 10 | +# |
| 11 | +# Requirements: |
| 12 | +# - Godot 4.6.x installed (resolved like run-headless-test.sh: $GODOT_BIN, |
| 13 | +# `godot` on PATH, or /Applications/Godot.app/Contents/MacOS/Godot on Mac). |
| 14 | +# - Matching Godot Web export templates installed (Mac: ~/Library/Application |
| 15 | +# Support/Godot/export_templates/<ver>/; Linux: ~/.local/share/godot/ |
| 16 | +# export_templates/<ver>/). |
| 17 | +# - python3 (for the static HTTP server). |
| 18 | +# - node + npm (for Playwright). The script will `npm install` Playwright and |
| 19 | +# `npx playwright install chromium` on first run if missing. |
| 20 | + |
| 21 | +project_dir="$(cd "$(dirname "$0")" && pwd)" |
| 22 | + |
| 23 | +# Resolve Godot binary |
| 24 | +if [ -n "${GODOT_BIN:-}" ]; then |
| 25 | + godot="$GODOT_BIN" |
| 26 | +elif command -v godot >/dev/null 2>&1; then |
| 27 | + godot="$(command -v godot)" |
| 28 | +elif [ "$(uname)" = "Darwin" ] && [ -x "/Applications/Godot.app/Contents/MacOS/Godot" ]; then |
| 29 | + godot="/Applications/Godot.app/Contents/MacOS/Godot" |
| 30 | +else |
| 31 | + echo "error: cannot find Godot binary. Set GODOT_BIN or put 'godot' on PATH." >&2 |
| 32 | + exit 2 |
| 33 | +fi |
| 34 | + |
| 35 | +if ! command -v python3 >/dev/null 2>&1; then |
| 36 | + echo "error: python3 not found (needed for the static HTTP server)." >&2 |
| 37 | + exit 2 |
| 38 | +fi |
| 39 | + |
| 40 | +if ! command -v node >/dev/null 2>&1; then |
| 41 | + echo "error: node not found (needed for the Playwright harness)." >&2 |
| 42 | + exit 2 |
| 43 | +fi |
| 44 | + |
| 45 | +port="${WEB_TEST_PORT:-8765}" |
| 46 | +timeout_ms="${WEB_TEST_TIMEOUT:-90000}" |
| 47 | + |
| 48 | +out_dir="$project_dir/.tmp-web" |
| 49 | +project_file="$project_dir/project.godot" |
| 50 | +backup_file="$project_dir/.tmp-project.godot.bak.$$" |
| 51 | + |
| 52 | +cleanup() { |
| 53 | + if [ -f "$backup_file" ]; then |
| 54 | + mv "$backup_file" "$project_file" |
| 55 | + fi |
| 56 | + if [ -n "${server_pid:-}" ] && kill -0 "$server_pid" 2>/dev/null; then |
| 57 | + kill "$server_pid" 2>/dev/null || true |
| 58 | + wait "$server_pid" 2>/dev/null || true |
| 59 | + fi |
| 60 | +} |
| 61 | +trap cleanup EXIT INT TERM |
| 62 | + |
| 63 | +echo "==> godot: $godot" |
| 64 | +echo "==> project: $project_dir" |
| 65 | +echo "==> output: $out_dir" |
| 66 | +echo "==> port: $port" |
| 67 | +echo |
| 68 | + |
| 69 | +# 1. Patch project.godot to use the web runner scene as main_scene. |
| 70 | +cp "$project_file" "$backup_file" |
| 71 | +awk ' |
| 72 | + /^run\/main_scene=/ { print "run/main_scene=\"res://scenes/test_web_runner.tscn\""; next } |
| 73 | + { print } |
| 74 | +' "$project_file" > "$project_file.tmp" |
| 75 | +mv "$project_file.tmp" "$project_file" |
| 76 | + |
| 77 | +# 2. Ensure Playwright is installed in the project dir. |
| 78 | +cd "$project_dir" |
| 79 | +if [ ! -d node_modules/playwright ]; then |
| 80 | + echo "==> installing playwright (first run)" |
| 81 | + if [ ! -f package.json ]; then |
| 82 | + npm init -y >/dev/null |
| 83 | + fi |
| 84 | + npm install --no-save --silent playwright |
| 85 | + npx --yes playwright install chromium |
| 86 | +fi |
| 87 | + |
| 88 | +# Tell Godot to skip node_modules during indexing/export (would otherwise be |
| 89 | +# bundled into the .pck because the Web preset uses export_filter=all_resources). |
| 90 | +# .gdignore is the Godot-native marker for "do not scan this directory". |
| 91 | +touch node_modules/.gdignore |
| 92 | + |
| 93 | +# 3. Import the project (needed before --export-release). |
| 94 | +echo "==> importing project" |
| 95 | +"$godot" --headless --path "$project_dir" --import || true |
| 96 | + |
| 97 | +# 4. Export the Web build. |
| 98 | +mkdir -p "$out_dir" |
| 99 | +echo "==> exporting Web build to $out_dir" |
| 100 | +"$godot" --headless --path "$project_dir" --export-release Web "$out_dir/index.html" |
| 101 | + |
| 102 | +if [ ! -f "$out_dir/index.html" ]; then |
| 103 | + echo "FAIL: export did not produce $out_dir/index.html" >&2 |
| 104 | + exit 1 |
| 105 | +fi |
| 106 | + |
| 107 | +# 5. Serve and run Playwright. |
| 108 | +echo "==> serving $out_dir on http://localhost:$port" |
| 109 | +(cd "$out_dir" && python3 -m http.server "$port" >/dev/null 2>&1) & |
| 110 | +server_pid=$! |
| 111 | + |
| 112 | +# Wait briefly for the server to come up. |
| 113 | +sleep 1 |
| 114 | + |
| 115 | +set +e |
| 116 | +node "$project_dir/web-test-runner.js" \ |
| 117 | + --url "http://localhost:$port/index.html" \ |
| 118 | + --markers "ALL_WEB_TESTS_PASSED" \ |
| 119 | + --timeout "$timeout_ms" |
| 120 | +test_status=$? |
| 121 | +set -e |
| 122 | + |
| 123 | +exit "$test_status" |
0 commit comments