nandi/vflutter_ffipublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Replace V with Nim 472eb49 · on main · nandithebull · 7h ago
check_web.sh · 59 lines · 2.5 KBBash Blame HistoryRaw
 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
#!/usr/bin/env bash
# End-to-end check of the web build: serve it, load it in headless Chrome,
# and confirm Nim actually produced a fractal in the browser.
#
# "It compiled" is not the bar here. dart:js_interop failures and wasm load
# failures both look like a clean build and a blank canvas, so this asserts on
# the rendered pixels and on the absence of uncaught exceptions.
set -euo pipefail
cd "$(dirname "$0")/.."

chrome="${CHROME_EXECUTABLE:-$(command -v google-chrome-stable || command -v google-chrome || command -v chromium || true)}"
[ -n "$chrome" ] || { echo "no Chrome found; set CHROME_EXECUTABLE"; exit 1; }
[ -d example/build/web ] || { echo "run 'just build-web' first"; exit 1; }
[ -f example/build/web/nimflutter.wasm ] || { echo "example/build/web/nimflutter.wasm missing"; exit 1; }

work="$(mktemp -d)"
port="${PORT:-8791}"
python3 -m http.server "$port" --bind 127.0.0.1 --directory example/build/web >/dev/null 2>&1 &
server=$!
trap 'kill $server 2>/dev/null || true; rm -rf "$work"' EXIT
sleep 2

"$chrome" --headless=new --no-sandbox --disable-dev-shm-usage \
  --enable-unsafe-swiftshader --virtual-time-budget=30000 \
  --window-size=1280,900 --screenshot="$work/shot.png" \
  --enable-logging=stderr --v=1 \
  "http://127.0.0.1:$port/index.html" >/dev/null 2>"$work/chrome.log"

# Uncaught Dart/JS exceptions surface as CONSOLE lines.
if grep -qE 'CONSOLE.*(Uncaught|Unhandled)' "$work/chrome.log"; then
  echo "FAIL uncaught exception in the browser:"
  grep -oE 'CONSOLE:[0-9]+\] "[^"]*' "$work/chrome.log" | head -5
  exit 1
fi

python3 - "$work/shot.png" <<'EOF'
import sys
from PIL import Image

im = Image.open(sys.argv[1]).convert('RGB')
w, h = im.size
# The canvas is the left ~70%; the right is the control panel.
canvas = im.crop((0, 0, int(w * 0.7), h))
colors = canvas.getcolors(maxcolors=1 << 24) or []
distinct = len(colors)
black = sum(n for n, c in colors if c == (0, 0, 0))
total = canvas.size[0] * canvas.size[1]

print(f"canvas {canvas.size[0]}x{canvas.size[1]}: {distinct} distinct colours, "
      f"{100 * black / total:.1f}% pure black")

# A blank/failed canvas is one flat colour. A real frame has the black
# interior of the set plus a smooth coloured exterior.
if distinct < 200:
    sys.exit(f"FAIL canvas has only {distinct} distinct colours — nothing rendered")
if not (0.05 < black / total < 0.75):
    sys.exit(f"FAIL black fraction {black / total:.2f} does not look like the set")
print("ok  Nim rendered a Mandelbrot frame in the browser")
EOF