Testing of the @doc-json output
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tessera-geotessera-jsoo: add Playwright browser test

Add browser test that compiles OCaml to JS via js_of_ocaml and verifies
fetch, npy parsing, and mosaic assembly work in a real browser.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+84
+5
tessera-geotessera-jsoo/test/dune
··· 1 + (executable 2 + (name test_browser) 3 + (modes js) 4 + (libraries tessera-geotessera-jsoo tessera-geotessera tessera-linalg tessera-npy js_of_ocaml) 5 + (preprocess (pps js_of_ocaml-ppx)))
+34
tessera-geotessera-jsoo/test/run_playwright.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 5 + MONO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" 6 + TEST_BUILD="$MONO_DIR/_build/default/tessera-geotessera-jsoo/test" 7 + 8 + # Build the JS test 9 + echo "Building test JS..." 10 + cd "$MONO_DIR" 11 + opam exec -- dune build tessera-geotessera-jsoo/test/test_browser.bc.js 12 + 13 + # Copy HTML to build dir 14 + cp "$SCRIPT_DIR/test_browser.html" "$TEST_BUILD/" 15 + 16 + # Start local server 17 + echo "Starting local server..." 18 + cd "$TEST_BUILD" 19 + python3 -m http.server 8765 & 20 + SERVER_PID=$! 21 + trap "kill $SERVER_PID 2>/dev/null || true" EXIT 22 + 23 + # Wait for server 24 + sleep 1 25 + 26 + echo "Server running on http://localhost:8765" 27 + echo "Run Playwright tests against http://localhost:8765/test_browser.html" 28 + echo "Server PID: $SERVER_PID (will be killed on exit)" 29 + 30 + # If called with --wait, keep server running for manual Playwright testing 31 + if [[ "${1:-}" == "--wait" ]]; then 32 + echo "Waiting... Press Ctrl+C to stop." 33 + wait $SERVER_PID 34 + fi
+12
tessera-geotessera-jsoo/test/test_browser.html
··· 1 + <!DOCTYPE html> 2 + <html> 3 + <head><title>tessera-geotessera-jsoo test</title></head> 4 + <body> 5 + <h1>tessera-geotessera-jsoo Browser Tests</h1> 6 + <p>Fetch: <span id="fetch-result">pending...</span></p> 7 + <p>Parse: <span id="parse-result">pending...</span></p> 8 + <p>Mosaic: <span id="mosaic-result">pending...</span></p> 9 + <p>Status: <span id="status">running...</span></p> 10 + <script src="test_browser.bc.js"></script> 11 + </body> 12 + </html>
+33
tessera-geotessera-jsoo/test/test_browser.ml
··· 1 + open Js_of_ocaml 2 + 3 + let set_result id text = 4 + let doc = Dom_html.document in 5 + Js.Opt.iter (doc##getElementById (Js.string id)) (fun el -> 6 + el##.textContent := Js.some (Js.string text)) 7 + 8 + let () = 9 + try 10 + (* Test 1: fetch a single scales file *) 11 + let url = "https://dl2.geotessera.org/v1/global_0.1_degree_representation/2024/grid_0.15_52.05/grid_0.15_52.05_scales.npy" in 12 + let data = Geotessera_jsoo.fetch url in 13 + let len = String.length data in 14 + set_result "fetch-result" 15 + (if len > 100 then Printf.sprintf "OK: %d bytes" len 16 + else Printf.sprintf "FAIL: only %d bytes" len); 17 + 18 + (* Test 2: parse the fetched npy *) 19 + let npy = Npy.of_string data |> Result.get_ok in 20 + let shape = Npy.shape npy in 21 + set_result "parse-result" 22 + (Printf.sprintf "OK: shape %s" 23 + (String.concat "x" (Array.to_list (Array.map string_of_int shape)))); 24 + 25 + (* Test 3: fetch_mosaic on a single-tile bbox *) 26 + let bbox = Geotessera.{ min_lon = 0.1; min_lat = 52.0; max_lon = 0.2; max_lat = 52.1 } in 27 + let mosaic, h, w = Geotessera_jsoo.fetch_mosaic ~year:2024 bbox in 28 + set_result "mosaic-result" 29 + (Printf.sprintf "OK: %d rows x %d cols, %dx%d" mosaic.rows mosaic.cols h w); 30 + 31 + set_result "status" "ALL PASSED" 32 + with exn -> 33 + set_result "status" (Printf.sprintf "FAILED: %s" (Printexc.to_string exn))