Skip to content

Commit b160e01

Browse files
committed
change conditions of build + debug
1 parent abc0203 commit b160e01

8 files changed

Lines changed: 89 additions & 32 deletions

File tree

.github/workflows/playwright.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ jobs:
2828
- name: Run Playwright tests
2929
run: pnpm exec playwright test
3030
env:
31+
CI: 'true'
3132
PLAYWRIGHT_E2E: '1'
33+
PLAYWRIGHT_DEBUG_NET: '1'
3234
PUBLIC_SUPABASE_URL: ${{ secrets.PUBLIC_SUPABASE_URL }}
3335
PUBLIC_SUPABASE_KEY: ${{ secrets.PUBLIC_SUPABASE_KEY }}
3436
PRIVATE_SUPABASE_KEY: ${{ secrets.PRIVATE_SUPABASE_KEY }}

playwright.config.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
/// <reference types="node" />
2-
import { defineConfig, devices } from '@playwright/test';
2+
import { defineConfig, devices } from "@playwright/test";
3+
4+
const onCI = !!process.env.CI;
35

46
/**
5-
* See https://playwright.dev/docs/test-configuration.
7+
* CI uses a production Node build — `vite dev` on Ubuntu runners was serving
8+
* SSR HTML while client modules never hydrated enough to call /api/teams.
9+
* Local keeps `vite dev` for fast iteration.
610
*/
11+
const webServerCommand = onCI
12+
? "pnpm build && PORT=5173 HOST=127.0.0.1 ORIGIN=http://127.0.0.1:5173 node build"
13+
: process.platform === "win32"
14+
? "pnpm dev"
15+
: "PLAYWRIGHT_E2E=1 pnpm dev";
16+
717
export default defineConfig({
8-
testDir: './tests',
9-
globalSetup: './tests/global-setup.ts',
18+
testDir: "./tests",
19+
globalSetup: "./tests/global-setup.ts",
1020
fullyParallel: true,
11-
forbidOnly: !!process.env.CI,
12-
retries: process.env.CI ? 2 : 0,
13-
workers: process.env.CI ? 1 : undefined,
14-
// Cold `vite dev` on CI can take >15s before client effects fire /api/teams.
21+
forbidOnly: onCI,
22+
retries: onCI ? 2 : 0,
23+
workers: onCI ? 1 : undefined,
1524
timeout: 60_000,
1625
expect: {
17-
timeout: process.env.CI ? 30_000 : 10_000,
26+
timeout: onCI ? 30_000 : 10_000,
1827
},
19-
reporter: 'html',
28+
reporter: "html",
2029
use: {
21-
baseURL: 'http://localhost:5173',
22-
trace: 'on-first-retry',
23-
serviceWorkers: 'block',
30+
baseURL: "http://127.0.0.1:5173",
31+
trace: "on-first-retry",
32+
serviceWorkers: "block",
2433
navigationTimeout: 60_000,
2534
},
2635

2736
projects: [
2837
{
29-
name: 'chromium',
30-
use: { ...devices['Desktop Chrome'] },
38+
name: "chromium",
39+
use: { ...devices["Desktop Chrome"] },
3140
},
3241
],
3342

3443
webServer: {
35-
// Inline env so PLAYWRIGHT_E2E is set before Vite snapshots process.env
36-
// (Kit's $env/dynamic/private is config-time; we also read process.env live).
37-
command:
38-
process.platform === 'win32'
39-
? 'pnpm dev'
40-
: 'PLAYWRIGHT_E2E=1 pnpm dev',
41-
url: 'http://localhost:5173',
42-
// Only reuse a server that was already started with PLAYWRIGHT_E2E=1.
43-
// A plain `pnpm dev` would miss SSR fixtures and greenwash false failures.
44-
reuseExistingServer:
45-
!process.env.CI && process.env.PLAYWRIGHT_E2E === '1',
46-
timeout: 120_000,
44+
command: webServerCommand,
45+
url: "http://127.0.0.1:5173",
46+
reuseExistingServer: !onCI && process.env.PLAYWRIGHT_E2E === "1",
47+
timeout: 180_000,
4748
env: {
4849
...process.env,
49-
PLAYWRIGHT_E2E: '1',
50+
PLAYWRIGHT_E2E: "1",
51+
PLAYWRIGHT_DEBUG_NET: onCI ? "1" : process.env.PLAYWRIGHT_DEBUG_NET ?? "",
5052
},
5153
},
5254
});

tests/abyss.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { test, expect } from "@playwright/test";
22
import { installApiMocks } from "./helpers";
3+
import { attachBrowserDebug } from "./debug";
34

4-
/** Client /api/* can lag SSR on cold Vite — keep waits aligned with config.timeout. */
55
const CLIENT_API_TIMEOUT = 45_000;
66

77
test.beforeEach(async ({ page }) => {
8+
attachBrowserDebug(page);
89
await installApiMocks(page);
910
});
1011

tests/debug.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { Page } from "@playwright/test";
2+
3+
/** Verbose browser/network logs for CI diagnosis (PLAYWRIGHT_DEBUG_NET=1 or CI). */
4+
export function attachBrowserDebug(page: Page): void {
5+
const enabled =
6+
process.env.PLAYWRIGHT_DEBUG_NET === "1" || process.env.CI === "true" || process.env.CI === "1";
7+
if (!enabled) return;
8+
9+
page.on("console", (msg) => {
10+
// eslint-disable-next-line no-console
11+
console.log(`[browser:${msg.type()}]`, msg.text());
12+
});
13+
page.on("pageerror", (err) => {
14+
// eslint-disable-next-line no-console
15+
console.log("[browser ERROR]", err.message);
16+
});
17+
page.on("request", (req) => {
18+
try {
19+
const p = new URL(req.url()).pathname;
20+
if (p.includes("/api/") || p.endsWith(".js") || p.includes("nodes/")) {
21+
// eslint-disable-next-line no-console
22+
console.log("[browser REQ]", req.method(), p);
23+
}
24+
} catch {
25+
/* ignore */
26+
}
27+
});
28+
page.on("requestfailed", (req) => {
29+
// eslint-disable-next-line no-console
30+
console.log(
31+
"[browser FAIL]",
32+
req.method(),
33+
req.url(),
34+
req.failure()?.errorText,
35+
);
36+
});
37+
}

tests/global-setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Warm Vite's dep optimizer / route modules before the suite so the first
3-
* client-hydrated tests do not burn their wait budgets on cold compiles.
2+
* Warm the app before the suite. On CI this hits the production Node server
3+
* (see playwright.config.ts); locally it warms vite dev.
44
*/
55
async function globalSetup() {
6-
const base = process.env.PLAYWRIGHT_BASE_URL ?? "http://localhost:5173";
6+
const base = process.env.PLAYWRIGHT_BASE_URL ?? "http://127.0.0.1:5173";
77
const paths = ["/", "/abyss", "/stygian", "/pulls", "/api/static"];
88
await Promise.all(
99
paths.map(async (path) => {

tests/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,20 @@ export async function installApiMocks(
8080
});
8181

8282
await page.route("**/api/teams", async (route: Route) => {
83+
if (process.env.PLAYWRIGHT_DEBUG_NET === "1" || process.env.CI) {
84+
// eslint-disable-next-line no-console
85+
console.log("[mock] /api/teams intercepted", route.request().method());
86+
}
8387
await route.fulfill({
8488
json: { abyssTeams, stygianTeams },
8589
});
8690
});
8791

8892
await page.route("**/api/nearmiss", async (route: Route) => {
93+
if (process.env.PLAYWRIGHT_DEBUG_NET === "1" || process.env.CI) {
94+
// eslint-disable-next-line no-console
95+
console.log("[mock] /api/nearmiss intercepted", route.request().method());
96+
}
8997
await route.fulfill({
9098
json: { nearMissTeams, nearMissPairs },
9199
});

tests/lazy-api.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { test, expect } from "@playwright/test";
22
import { installApiMocks, trackApiPaths } from "./helpers";
3+
import { attachBrowserDebug } from "./debug";
34

45
const CLIENT_API_TIMEOUT = 45_000;
56

67
test("home and settings do not fetch owned teams or near-miss", async ({
78
page,
89
}) => {
10+
attachBrowserDebug(page);
911
await installApiMocks(page);
1012
const hits = trackApiPaths(page, ["/api/teams", "/api/nearmiss"]);
1113

@@ -23,6 +25,7 @@ test("home and settings do not fetch owned teams or near-miss", async ({
2325
});
2426

2527
test("abyss fetches /api/teams but not /api/nearmiss", async ({ page }) => {
28+
attachBrowserDebug(page);
2629
await installApiMocks(page);
2730
const hits = trackApiPaths(page, ["/api/teams", "/api/nearmiss"]);
2831

@@ -40,6 +43,7 @@ test("abyss fetches /api/teams but not /api/nearmiss", async ({ page }) => {
4043
});
4144

4245
test("pulls fetches /api/teams and /api/nearmiss", async ({ page }) => {
46+
attachBrowserDebug(page);
4347
await installApiMocks(page);
4448
const hits = trackApiPaths(page, ["/api/teams", "/api/nearmiss"]);
4549

tests/pulls.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import {
44
NEAR_MISS_SINGLE,
55
STYGIAN_OWNED_BASELINE,
66
} from "./helpers";
7+
import { attachBrowserDebug } from "./debug";
78

89
const CLIENT_API_TIMEOUT = 45_000;
910

1011
test("pulls ranks a mocked near-miss suggestion", async ({ page }) => {
12+
attachBrowserDebug(page);
1113
await installApiMocks(page, {
1214
stygianTeams: [STYGIAN_OWNED_BASELINE],
1315
nearMissTeams: [NEAR_MISS_SINGLE],
@@ -33,6 +35,7 @@ test("pulls ranks a mocked near-miss suggestion", async ({ page }) => {
3335
test("pulls shows empty state when near-miss has nothing useful", async ({
3436
page,
3537
}) => {
38+
attachBrowserDebug(page);
3639
await installApiMocks(page, {
3740
stygianTeams: [STYGIAN_OWNED_BASELINE],
3841
nearMissTeams: [],

0 commit comments

Comments
 (0)