Skip to content

Commit 0dd21b1

Browse files
committed
test(ts): run browser tests in parallel
1 parent d07d053 commit 0dd21b1

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

ts/scripts/run_playwright.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ async function main() {
6262
},
6363
);
6464

65+
// Handle server process termination
66+
serverProcess.on("exit", (code, signal) => {
67+
if (code !== null && code !== 0) {
68+
console.error(`[Server] Server process exited with code ${code}`);
69+
}
70+
if (signal) {
71+
console.log(`[Server] Server process terminated by signal ${signal}`);
72+
}
73+
});
74+
6575
// Log server output for debugging
6676
serverProcess.stdout.on("data", (data) => {
6777
console.log(`[Server] ${data.toString().trim()}`);
@@ -95,6 +105,8 @@ async function main() {
95105

96106
if (response.statusCode === 200) {
97107
console.log("✅ Test server is ready!");
108+
// Wait a bit longer to ensure server is fully stable
109+
await new Promise((resolve) => setTimeout(resolve, 2000));
98110
return true;
99111
}
100112
} catch (_error) {

ts/test/browser-npm/playwright.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @ts-check
22

3+
import process from "node:process";
4+
35
/**
46
* @see https://playwright.dev/docs/test-configuration
57
*/
@@ -12,7 +14,7 @@ const config = {
1214
/* Retry on CI only */
1315
retries: 0,
1416
/* Opt out of parallel tests on CI. */
15-
workers: 1,
17+
workers: process.env.CI ? 2 : undefined, // Use default number of workers (CPU cores) locally, 2 on CI
1618
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
1719
reporter: "list",
1820
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */

ts/test/browser/server.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Simple test server for browser tests
2+
import { serveFile } from "@std/http/file-server";
3+
import { join } from "@std/path";
4+
5+
const PORT = 3000;
6+
7+
async function handler(req: Request): Promise<Response> {
8+
const url = new URL(req.url);
9+
10+
// Serve the test HTML file for root requests
11+
if (url.pathname === "/") {
12+
const filePath = join(
13+
Deno.cwd(),
14+
"test",
15+
"browser",
16+
"fixtures",
17+
"index.html",
18+
);
19+
return await serveFile(req, filePath);
20+
}
21+
22+
// Serve static files from the src directory
23+
if (url.pathname.startsWith("/src/")) {
24+
const filePath = join(Deno.cwd(), url.pathname.substring(1));
25+
try {
26+
return await serveFile(req, filePath);
27+
} catch {
28+
return new Response("Not Found", { status: 404 });
29+
}
30+
}
31+
32+
// Serve other test fixtures
33+
if (url.pathname.startsWith("/test/")) {
34+
const filePath = join(Deno.cwd(), url.pathname.substring(1));
35+
try {
36+
return await serveFile(req, filePath);
37+
} catch {
38+
return new Response("Not Found", { status: 404 });
39+
}
40+
}
41+
42+
// Serve the npm test page
43+
if (url.pathname === "/npm-test") {
44+
const filePath = join(Deno.cwd(), "test", "browser-npm", "index.html");
45+
return await serveFile(req, filePath);
46+
}
47+
48+
// Serve the npm package files
49+
if (url.pathname.startsWith("/npm/")) {
50+
const filePath = join(Deno.cwd(), url.pathname.substring(1));
51+
try {
52+
return await serveFile(req, filePath);
53+
} catch {
54+
return new Response("Not Found", { status: 404 });
55+
}
56+
}
57+
58+
return new Response("Not Found", { status: 404 });
59+
}
60+
61+
console.log(`Test server running at http://localhost:${PORT}`);
62+
console.log(`Listening on http://0.0.0.0:${PORT}/ (http://localhost:${PORT}/)`);
63+
64+
try {
65+
const server = Deno.serve({ port: PORT }, handler);
66+
await server.finished;
67+
} catch (error) {
68+
console.error("Failed to start server:", error);
69+
Deno.exit(1);
70+
}

0 commit comments

Comments
 (0)