65 lines
2.7 KiB
JavaScript
65 lines
2.7 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { createReadStream, statSync } from "node:fs";
|
|
import { createServer } from "node:http";
|
|
import { extname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import { chromium } from "../../app/node_modules/playwright/index.mjs";
|
|
|
|
const webRoot = resolve(fileURLToPath(new URL("../..", import.meta.url)));
|
|
const contentTypes = {
|
|
".html": "text/html; charset=utf-8",
|
|
".js": "text/javascript; charset=utf-8",
|
|
".mjs": "text/javascript; charset=utf-8",
|
|
".json": "application/json; charset=utf-8",
|
|
".wasm": "application/wasm",
|
|
".zip": "application/zip",
|
|
};
|
|
const server = createServer((request, response) => {
|
|
try {
|
|
const pathname = decodeURIComponent(new URL(request.url, "http://localhost").pathname);
|
|
const path = resolve(webRoot, `.${pathname}`);
|
|
if (!path.startsWith(webRoot) || !statSync(path).isFile()) {
|
|
response.writeHead(404).end("not found");
|
|
return;
|
|
}
|
|
response.writeHead(200, { "Content-Type": contentTypes[extname(path)] || "application/octet-stream" });
|
|
createReadStream(path).pipe(response);
|
|
} catch {
|
|
response.writeHead(404).end("not found");
|
|
}
|
|
});
|
|
await new Promise((resolveListen) => server.listen(0, "127.0.0.1", resolveListen));
|
|
const address = server.address();
|
|
const browser = await chromium.launch({ headless: true });
|
|
try {
|
|
const page = await browser.newPage();
|
|
await page.goto(`http://127.0.0.1:${address.port}/tests/browser/python_remap_pyodide_browser_smoke.html`);
|
|
await page.waitForFunction(
|
|
() => document.getElementById("status")?.textContent.includes("python_remap_pyodide_browser_runtime=ok"),
|
|
null,
|
|
{ timeout: 60000 },
|
|
);
|
|
const status = await page.locator("#status").textContent();
|
|
assert.match(status, /python_remap_queuebuster_first_yield=2/);
|
|
assert.match(status, /python_remap_execution_enabled=1/);
|
|
assert.match(status, /python_remap_promotion_allowed=1/);
|
|
console.log(status);
|
|
|
|
const appPage = await browser.newPage();
|
|
await appPage.goto(`http://127.0.0.1:${address.port}/app/dist/index.html`);
|
|
const appReadiness = await appPage.evaluate(async () => {
|
|
await window.webRtcp5AxisSimulation.pythonRemapRuntimeReady;
|
|
return window.webRtcp5AxisSimulation.getState().pythonRemapRuntimeReadiness;
|
|
});
|
|
assert.equal(appReadiness.runtimeExecutionReady, true);
|
|
assert.equal(appReadiness.lifecycleReady, true);
|
|
assert.equal(appReadiness.executionEnabled, true);
|
|
assert.equal(appReadiness.promotionAllowed, true);
|
|
assert.equal(appReadiness.firstYield, 2);
|
|
console.log("python_remap_target_web_integration=ok");
|
|
} finally {
|
|
await browser.close();
|
|
await new Promise((resolveClose) => server.close(resolveClose));
|
|
}
|