9f97f3abbe
CI - Node Bindings / Build darwin-arm64 (push) Waiting to run
CI - Node Bindings / Build darwin-x64 (push) Waiting to run
CI - Node Bindings / Test win32-x64-msvc (push) Blocked by required conditions
CI - Node Bindings / Build linux-arm64-gnu (push) Waiting to run
CI - Node Bindings / Build linux-x64-gnu (push) Waiting to run
CI - Node Bindings / Build linux-x64-musl (push) Waiting to run
CI - Node Bindings / Build win32-arm64-msvc (push) Waiting to run
CI - Node Bindings / Build win32-x64-msvc (push) Waiting to run
CI - Node Bindings / Test darwin-arm64 (push) Blocked by required conditions
CI - Node Bindings / Test darwin-x64 (push) Blocked by required conditions
CI - Node Bindings / Test linux-x64-gnu (push) Blocked by required conditions
CI - Node Bindings / Test linux-x64-musl (push) Blocked by required conditions
CI - Node Bindings / Test win32-arm64-msvc (push) Blocked by required conditions
CI - Python Bindings / Build aarch64-pc-windows-msvc (push) Waiting to run
CI - Python Bindings / Build x86_64-pc-windows-msvc (push) Waiting to run
CI - Python Bindings / Build x86_64-apple-darwin (push) Waiting to run
CI - Python Bindings / Build aarch64-apple-darwin (push) Waiting to run
CI - Python Bindings / Build aarch64-unknown-linux-gnu (push) Waiting to run
CI - Python Bindings / Test x86_64-apple-darwin (push) Blocked by required conditions
CI - Python Bindings / Test aarch64-apple-darwin (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-unknown-linux-gnu (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-unknown-linux-musl (push) Blocked by required conditions
CI - Python Bindings / Test aarch64-pc-windows-msvc (push) Blocked by required conditions
CI - Python Bindings / Test x86_64-pc-windows-msvc (push) Blocked by required conditions
CI / build-and-test (macos-26-intel) (push) Waiting to run
CI / build-and-test (macos-latest) (push) Waiting to run
CI / build-and-test (windows-11-arm) (push) Waiting to run
CI / build-and-test (windows-latest) (push) Waiting to run
CI - Python Bindings / sdist (push) Failing after 1s
CI - Python Bindings / Build x86_64-unknown-linux-musl (push) Failing after 1s
CI / fmt (push) Failing after 1s
E2E Output Validation / compare-outputs (push) Failing after 1s
Sync Docs to Developer Hub / sync-docs (push) Failing after 1s
CI - Python Bindings / Build x86_64-unknown-linux-gnu (push) Failing after 1s
CI - WASM Bindings / Build WASM (push) Failing after 0s
CI / clippy (push) Failing after 1s
CI / build-and-test (ubuntu-latest) (push) Failing after 0s
CI - WASM Bindings / Edge runtime PDF parse test (push) Has been skipped
CI - WASM Bindings / Browser PDF parse test (push) Has been skipped
E2E Output Validation / upload-dataset (push) Waiting to run
Deploy Demo to GitHub Pages / deploy (push) Failing after 1s
CI / build-docker-image (push) Failing after 3s
113 lines
3.3 KiB
JavaScript
113 lines
3.3 KiB
JavaScript
/**
|
|
* Playwright test that loads the LiteParse WASM module in a real browser
|
|
* and verifies it can parse a PDF end-to-end.
|
|
*
|
|
* Usage: node scripts/browser-compat/wasm-test.mjs
|
|
*
|
|
* Requires: playwright (npx playwright install chromium)
|
|
* Expects: packages/wasm/pkg/ to contain the built WASM files
|
|
* demo/docs/apple-10k-2024.pdf to exist
|
|
*/
|
|
|
|
import { createServer } from "node:http";
|
|
import { readFile } from "node:fs/promises";
|
|
import { resolve, extname } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { chromium } from "playwright";
|
|
|
|
const ROOT = resolve(fileURLToPath(import.meta.url), "../../..");
|
|
|
|
const MIME_TYPES = {
|
|
".html": "text/html",
|
|
".js": "application/javascript",
|
|
".wasm": "application/wasm",
|
|
".pdf": "application/pdf",
|
|
".json": "application/json",
|
|
};
|
|
|
|
function startServer() {
|
|
return new Promise((resolvePromise) => {
|
|
const server = createServer(async (req, res) => {
|
|
const url = new URL(req.url, "http://localhost");
|
|
const filePath = resolve(ROOT, "." + url.pathname);
|
|
|
|
// Basic security: don't serve outside ROOT
|
|
if (!filePath.startsWith(ROOT)) {
|
|
res.writeHead(403);
|
|
res.end("Forbidden");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const data = await readFile(filePath);
|
|
const ext = extname(filePath);
|
|
res.writeHead(200, {
|
|
"Content-Type": MIME_TYPES[ext] || "application/octet-stream",
|
|
"Cross-Origin-Opener-Policy": "same-origin",
|
|
"Cross-Origin-Embedder-Policy": "require-corp",
|
|
});
|
|
res.end(data);
|
|
} catch {
|
|
res.writeHead(404);
|
|
res.end("Not found");
|
|
}
|
|
});
|
|
|
|
server.listen(0, "127.0.0.1", () => {
|
|
const port = server.address().port;
|
|
resolvePromise({ server, port });
|
|
});
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
const { server, port } = await startServer();
|
|
const baseUrl = `http://127.0.0.1:${port}`;
|
|
console.log(`Static server listening on ${baseUrl}`);
|
|
|
|
let browser;
|
|
try {
|
|
browser = await chromium.launch();
|
|
const page = await browser.newPage();
|
|
|
|
// Collect console errors
|
|
const errors = [];
|
|
page.on("pageerror", (err) => errors.push(err.message));
|
|
|
|
console.log("Navigating to test page...");
|
|
await page.goto(`${baseUrl}/scripts/browser-compat/wasm-test.html`);
|
|
|
|
// Wait for either #result or #error to appear (up to 120s for large PDFs)
|
|
await page.waitForSelector("#result[style*='block'], #error[style*='block']", {
|
|
timeout: 120_000,
|
|
});
|
|
|
|
const errorText = await page.locator("#error").textContent();
|
|
if (errorText) {
|
|
console.error(`FAIL: ${errorText}`);
|
|
if (errors.length) console.error("Console errors:", errors);
|
|
process.exit(1);
|
|
}
|
|
|
|
const resultText = await page.locator("#result").textContent();
|
|
const pages = await page.locator("#result").getAttribute("data-pages");
|
|
const textLength = await page.locator("#result").getAttribute("data-text-length");
|
|
|
|
console.log(`PASS: ${resultText}`);
|
|
console.log(` Pages: ${pages}`);
|
|
console.log(` Text length: ${textLength}`);
|
|
|
|
if (errors.length) {
|
|
console.warn("Browser console errors (non-fatal):", errors);
|
|
}
|
|
} finally {
|
|
if (browser) await browser.close();
|
|
server.close();
|
|
}
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("Test runner failed:", err);
|
|
process.exit(1);
|
|
});
|