3327 bytes
#!/bin/sh
set -eu
top="$(git rev-parse --show-toplevel)"
cli="$top/anbot.mjs"
chrome=${ANBOT_TEST_CHROME:-"$HOME/.cache/ms-playwright/chromium-1248/chrome-linux64/chrome"}
scratch=$(mktemp -d)
nodePort=${ANBOT_TEST_BROWSER_NODE_PORT:-18798}
staticPort=${ANBOT_TEST_BROWSER_STATIC_PORT:-18799}
nodeServer=
staticServer=
cleanup() {
for pid in "$nodeServer" "$staticServer"; do
if [ -n "$pid" ]; then
kill "$pid" 2>/dev/null || :
wait "$pid" 2>/dev/null || :
fi
done
rm -r "$scratch"
}
trap cleanup EXIT
trap 'exit 1' INT TERM
test -x "$chrome" || { echo "Chrome not found at $chrome" >&2; exit 1; }
git init -q -b main --object-format=sha1 "$scratch/source"
printf 'browser fixture\n' >"$scratch/source/README.md"
git -C "$scratch/source" add .
git -C "$scratch/source" -c user.name=Test -c user.email=test@example.invalid commit -q -m 'Browser fixture'
head=$(git -C "$scratch/source" rev-parse HEAD)
node "$cli" publish --data "$scratch/node" --source "$scratch/source" --branch main --port "$nodePort" >"$scratch/pub.json"
repoId=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).repoId' "$scratch/pub.json")
updateId=$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).updateId' "$scratch/pub.json")
postText='Browser-feed-post'
postId=$(node "$cli" post --data "$scratch/node" --text "$postText" |
node -pe 'JSON.parse(require("node:fs").readFileSync(0)).id')
node "$cli" serve --data "$scratch/node" --port "$nodePort" >"$scratch/url" &
nodeServer=$!
attempts=0
until test -s "$scratch/url"; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 50 ]; then echo 'Timed out waiting for node' >&2; exit 1; fi
sleep 0.1
done
node "$top/test/browser/serve.mjs" --root "$top" --port "$staticPort" --result-file "$scratch/result.json" >"$scratch/static.url" &
staticServer=$!
attempts=0
until test -s "$scratch/static.url"; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 50 ]; then echo 'Timed out waiting for static server' >&2; exit 1; fi
sleep 0.1
done
# The harness page posts its outcome to the static server when its async
# work finishes; poll for that file instead of dumping the DOM, which
# races the page's real async work under virtual time.
"$chrome" --headless=new --no-sandbox --disable-gpu --disable-dev-shm-usage --no-first-run \
--user-data-dir="$scratch/profile" \
"http://127.0.0.1:$staticPort/test/browser/harness.html#node=http://127.0.0.1:$nodePort&repo=$repoId&update=$updateId&post=$postId&postText=$postText" \
>"$scratch/chrome.log" 2>&1 &
chromePid=$!
attempts=0
until test -s "$scratch/result.json"; do
attempts=$((attempts + 1))
if [ "$attempts" -ge 120 ]; then
echo 'Timed out waiting for the browser harness result' >&2
kill "$chromePid" 2>/dev/null || :
wait "$chromePid" 2>/dev/null || :
echo 'Chrome log:' >&2
cat "$scratch/chrome.log" >&2
exit 1
fi
sleep 0.5
done
kill "$chromePid" 2>/dev/null || :
wait "$chromePid" 2>/dev/null || :
if grep -q '"status":"PASS"' "$scratch/result.json"; then
printf 'PASS: browser harness ran the core, both store backends, and a pull at %s.\n' "$head"
else
echo 'Browser harness failed. Harness output:' >&2
cat "$scratch/result.json" >&2
echo >&2
echo 'Chrome log:' >&2
cat "$scratch/chrome.log" >&2
exit 1
fi
Git ยท Social feed