Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/pure-test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
// SPDX-License-Identifier: Apache-2.0

/**
* pure-test CLI - discovers and runs test files.
Expand Down
1 change: 1 addition & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* build.mjs - Clean build with comment stripping.
*
Expand Down
1 change: 1 addition & 0 deletions scripts/coverage-all.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* coverage-all.mjs - Per-runtime coverage orchestrator.
*
Expand Down
1 change: 1 addition & 0 deletions scripts/prepublish.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* prepublish.mjs - Pre-publish gate.
*
Expand Down
1 change: 1 addition & 0 deletions scripts/test-ci.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* test-ci.mjs - Run the full CI test matrix locally.
*
Expand Down
1 change: 1 addition & 0 deletions scripts/test-matrix.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* test-matrix.mjs - Run full test suite across all available runtimes.
* Used inside Docker containers and natively on macOS.
Expand Down
1 change: 1 addition & 0 deletions tests/browser-test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Browser smoke test via Playwright.
*
Expand Down
91 changes: 91 additions & 0 deletions tests/browser/run.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Run the core smoke test inside a real browser via Playwright.
*
* Serves dist/ and test files via a local HTTP server, opens a headless
* Chromium page that loads smoke-core.mjs as an ES module, and collects
* the RunSmokeCore result.
*
* Usage: node tests/browser/run.mjs
* Requires: playwright devDependency (npx playwright install chromium)
*/

import { readFile } from "node:fs/promises";
import { createServer } from "node:http";
import { extname, resolve } from "node:path";
import { chromium } from "playwright";

const ROOT = resolve(new URL("../../", import.meta.url).pathname);

const MIME = {
".js": "text/javascript",
".mjs": "text/javascript",
".html": "text/html",
".json": "application/json",
};

const HTML =
"<!DOCTYPE html>\n<html>\n<head><title>pure-test browser smoke test</title></head>\n" +
"<body>\n<script type=\"module\">\n" +
"import { runSmokeCore } from \"./tests/smoke-core.mjs\";\n" +
"import * as lib from \"./dist/index.js\";\n\n" +
"const result = await runSmokeCore(lib);\n" +
"window.__testResult = result;\n" +
"</script>\n</body>\n</html>";

const server = createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost");

// Serve the test harness HTML at a dedicated path
if (url.pathname === "/__test__") {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(HTML);
return;
}

// Serve static files from project root
const filePath = resolve(ROOT, url.pathname.slice(1));
if (!filePath.startsWith(ROOT)) {
res.writeHead(403);
res.end("Forbidden");
return;
}

try {
const content = await readFile(filePath);
const ext = extname(filePath);
res.writeHead(200, { "Content-Type": MIME[ext] || "application/octet-stream" });
res.end(content);
} catch {
res.writeHead(404);
res.end("Not found");
}
});

await new Promise((r) => server.listen(0, r));
const port = server.address().port;

const browser = await chromium.launch();
const page = await browser.newPage();

page.on("console", (msg) => console.log(" [browser] " + msg.text()));
page.on("pageerror", (err) => console.log(" [browser error] " + err.message));

await page.goto("http://localhost:" + port + "/__test__");
await page.waitForFunction(() => window.__testResult !== undefined, {
timeout: 30000,
});
const result = await page.evaluate(() => window.__testResult);

for (const line of result.logs) {
console.log(line);
}

await browser.close();
server.close();

if (result.failed > 0) {
console.log("\nBrowser: " + result.failed + " test(s) failed");
process.exit(1);
}
console.log("\nBrowser (Chromium): all " + result.passed + " tests passed");
1 change: 1 addition & 0 deletions tests/cli.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* CLI integration tests: spawn bin/pure-test.mjs and assert on exit codes / output.
*
Expand Down
1 change: 1 addition & 0 deletions tests/deno-adapter.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Deno adapter smoke test.
*
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/example.test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from "../../dist/index.js";

describe("example", () => {
Expand Down
1 change: 1 addition & 0 deletions tests/grep-test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Tests for setGrep / --grep filtering.
*
Expand Down
1 change: 1 addition & 0 deletions tests/only-test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Tests for it.only and describe.only.
*
Expand Down
1 change: 1 addition & 0 deletions tests/self-test.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: Apache-2.0
/**
* Self-test: the test runner testing itself.
*
Expand Down
Loading
Loading