@@ -207,18 +207,47 @@ jobs:
207207 if : ${{ matrix.platform.wasm }}
208208 id : wasm_render
209209 run : |
210+ cat > /tmp/wasm-ci/index.html << 'HTML'
211+ <!DOCTYPE html>
212+ <html><body>
213+ <script type="module">
214+ import init, { create_renderer } from "./pkg/clypra_render_wasm.js";
215+ async function run() {
216+ await init();
217+ const r = await create_renderer();
218+ window._adapter = r.adapter_info();
219+ const fixtures = ["minimal","raster"];
220+ window._out = {};
221+ for (const f of fixtures) {
222+ const json = await fetch("./" + f + "-request.json").then(x=>x.text());
223+ window._out[f] = Array.from(await r.render_frame(json));
224+ }
225+ window._done = true;
226+ }
227+ run().catch(e => {
228+ console.error("[runner-err]", e);
229+ window._err = String(e);
230+ window._done = true;
231+ });
232+ </script>
233+ </body></html>
234+ HTML
235+
210236 cat > /tmp/wasm-puppeteer/wasm-render.mjs << 'SCRIPT'
211237 import puppeteer from "puppeteer";
212238 import { readFileSync, writeFileSync, mkdirSync } from "fs";
213239 import { createServer } from "http";
214240 import { extname, join } from "path";
215241 const SERVE_DIR = "/tmp/wasm-ci";
216242 const PORT = 8799;
217- const MIME = { ".js": "application/javascript", ".wasm": "application/wasm", ".json": "application/json" };
243+ const MIME = { ".html": "text/html", ". js": "application/javascript", ".wasm": "application/wasm", ".json": "application/json" };
218244 const server = createServer((req, res) => {
245+ const parsedUrl = req.url.split("?")[0];
246+ const filePath = parsedUrl === "/" ? join(SERVE_DIR, "index.html") : join(SERVE_DIR, parsedUrl);
247+ res.setHeader("Access-Control-Allow-Origin", "*");
219248 try {
220- const data = readFileSync(join(SERVE_DIR, req.url.split("?")[0]) );
221- res.writeHead(200, { "Content-Type": MIME[extname(req.url.split("?")[0] )] ?? "application/octet-stream" });
249+ const data = readFileSync(filePath );
250+ res.writeHead(200, { "Content-Type": MIME[extname(filePath )] ?? "application/octet-stream" });
222251 res.end(data);
223252 } catch { res.writeHead(404); res.end(); }
224253 }).listen(PORT);
@@ -230,22 +259,7 @@ jobs:
230259 const page = await browser.newPage();
231260 page.on("console", msg => console.log(`[browser-console] ${msg.type()}: ${msg.text()}`));
232261 page.on("pageerror", e => console.error(`[browser-pageerror] ${e}`));
233- await page.setContent(`<!DOCTYPE html><html><body><script type="module">
234- import init, { create_renderer } from "http://localhost:${PORT}/pkg/clypra_render_wasm.js";
235- async function run() {
236- await init();
237- const r = await create_renderer();
238- window._adapter = r.adapter_info();
239- const fixtures = ["minimal","raster"];
240- window._out = {};
241- for (const f of fixtures) {
242- const json = await fetch("http://localhost:${PORT}/" + f + "-request.json").then(x=>x.text());
243- window._out[f] = Array.from(await r.render_frame(json));
244- }
245- window._done = true;
246- }
247- run().catch(e => { window._err = String(e); window._done = true; });
248- <\/script></body></html>`);
262+ await page.goto(`http://localhost:${PORT}/index.html`);
249263 await page.waitForFunction("window._done === true", { timeout: 60000 });
250264 const err = await page.evaluate(() => window._err);
251265 if (err) { console.error("WASM_ERROR:" + err); process.exit(1); }
0 commit comments