this repo has no description

tessera-viz-jsoo: add Playwright browser test

Tests PNG encoding and data URL generation in a web worker.
Verified: 4x4 RGBA image encodes to valid PNG, renders as <img>.

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

+82
+5
tessera-viz-jsoo/test/dune
··· 1 + (executable 2 + (name test_browser) 3 + (modes js) 4 + (libraries tessera-viz-jsoo tessera-viz tessera-linalg js_of_ocaml) 5 + (preprocess (pps js_of_ocaml-ppx)))
+29
tessera-viz-jsoo/test/test_browser.html
··· 1 + <!DOCTYPE html> 2 + <html> 3 + <head><title>tessera-viz-jsoo test</title></head> 4 + <body> 5 + <h1>tessera-viz-jsoo Browser Tests</h1> 6 + <p>PNG: <span id="png-result">pending...</span></p> 7 + <p>URL: <span id="url-result">pending...</span></p> 8 + <p>Status: <span id="status">running...</span></p> 9 + <p>Image: <img id="test-image" alt="test image" /></p> 10 + <script> 11 + var worker = new Worker('test_browser.bc.js'); 12 + worker.onmessage = function(e) { 13 + var idx = e.data.indexOf(':'); 14 + if (idx === -1) return; 15 + var id = e.data.substring(0, idx); 16 + var text = e.data.substring(idx + 1); 17 + if (id === 'img-src') { 18 + document.getElementById('test-image').src = text; 19 + } else { 20 + var el = document.getElementById(id); 21 + if (el) el.textContent = text; 22 + } 23 + }; 24 + worker.onerror = function(e) { 25 + document.getElementById('status').textContent = 'FAILED: ' + e.message; 26 + }; 27 + </script> 28 + </body> 29 + </html>
+48
tessera-viz-jsoo/test/test_browser.ml
··· 1 + open Js_of_ocaml 2 + 3 + let post_result id text = 4 + ignore (Js.Unsafe.global##postMessage (Js.string (id ^ ":" ^ text))) 5 + 6 + let () = 7 + try 8 + (* Create a 4x4 test image: red/green/blue/white quadrants *) 9 + let w = 4 and h = 4 in 10 + let data = Bigarray.Array1.create Bigarray.int8_unsigned Bigarray.c_layout (w * h * 4) in 11 + for y = 0 to h - 1 do 12 + for x = 0 to w - 1 do 13 + let off = (y * w + x) * 4 in 14 + let r, g, b = 15 + if y < 2 && x < 2 then (255, 0, 0) 16 + else if y < 2 then (0, 255, 0) 17 + else if x < 2 then (0, 0, 255) 18 + else (255, 255, 255) 19 + in 20 + Bigarray.Array1.set data off r; 21 + Bigarray.Array1.set data (off + 1) g; 22 + Bigarray.Array1.set data (off + 2) b; 23 + Bigarray.Array1.set data (off + 3) 255 24 + done 25 + done; 26 + let img = Viz.{ data; width = w; height = h } in 27 + 28 + (* Test 1: PNG encoding produces valid data *) 29 + let png = Viz.png_of_rgba img in 30 + post_result "png-result" 31 + (Printf.sprintf "OK: %d bytes, magic=0x%02x%c%c%c" 32 + (String.length png) (Char.code png.[0]) png.[1] png.[2] png.[3]); 33 + 34 + (* Test 2: data URL generation *) 35 + let url = Viz_jsoo.to_data_url img in 36 + let prefix = "data:image/png;base64," in 37 + let has_prefix = String.length url > String.length prefix && 38 + String.sub url 0 (String.length prefix) = prefix in 39 + post_result "url-result" 40 + (if has_prefix then Printf.sprintf "OK: %d chars" (String.length url) 41 + else "FAIL: bad prefix"); 42 + 43 + (* Post the data URL for the page to display as an image *) 44 + post_result "img-src" url; 45 + 46 + post_result "status" "ALL PASSED" 47 + with exn -> 48 + post_result "status" (Printf.sprintf "FAILED: %s" (Printexc.to_string exn))