Skip to content

Commit 74dc666

Browse files
committed
fix(tests): integration tests use running daemon + watch mode
Integration tests now connect to the running daemon (port 52745) instead of creating an isolated headless test server. Added beforeAll watch-mode switch and afterAll headless restore. All 9 tests pass (119s). Made-with: Cursor
1 parent f488d2b commit 74dc666

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

tests/booking.integration.test.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,41 @@
11
/**
22
* L2 — Live Integration Tests
33
*
4-
* Tests against real secure.booking.com — requires authentication.
5-
* Run ONLY locally after: browserkit login booking
4+
* Tests against real secure.booking.com — requires authentication AND watch mode.
5+
* Run ONLY locally after:
6+
* 1. browserkit login booking
7+
* 2. browserkit start --config browserkit.config.js (daemon running on port 52745)
68
*
79
* Usage: pnpm test:integration
810
*
9-
* These tests are excluded from CI because:
10-
* 1. They require a real Booking.com account session
11-
* 2. Booking.com uses Cloudflare + fingerprinting (blocks CI IPs)
12-
* 3. They expose personal booking data
11+
* IMPORTANT: secure.booking.com blocks headless Chrome. These tests connect to
12+
* the running daemon and switch to watch mode automatically.
1313
*/
1414
import { describe, it, expect, beforeAll, afterAll } from "vitest";
15-
import bookingAdapter from "../src/index.js";
16-
import { createTestAdapterServer, type TestAdapterServer } from "@browserkit/core/testing";
1715
import { createTestMcpClient, type TestMcpClient } from "@browserkit/core/testing";
1816
import type { Booking, BookingDetail } from "../src/scraper.js";
1917

20-
// ── Shared server ─────────────────────────────────────────────────────────────
18+
// Connect to the running daemon (not a fresh test server — needs real auth)
19+
const MCP_URL = process.env["BOOKING_MCP_URL"] ?? "http://127.0.0.1:52745/mcp";
20+
21+
// ── Shared client ─────────────────────────────────────────────────────────────
2122

22-
let server: TestAdapterServer;
2323
let client: TestMcpClient;
2424

2525
beforeAll(async () => {
26-
server = await createTestAdapterServer(bookingAdapter);
27-
client = await createTestMcpClient(server.url);
26+
client = await createTestMcpClient(MCP_URL);
27+
28+
// Switch to watch mode — required for secure.booking.com access
29+
await client.callTool("browser", { action: "set_mode", mode: "watch" });
30+
31+
// Navigate to www.booking.com (where session cookies work)
32+
await client.callTool("browser", { action: "navigate", url: "https://www.booking.com/" });
2833
}, 30_000);
2934

3035
afterAll(async () => {
36+
// Switch back to headless when done
37+
await client.callTool("browser", { action: "set_mode", mode: "headless" }).catch(() => {});
3138
await client.close();
32-
await server.stop();
3339
});
3440

3541
// ── Auth check ────────────────────────────────────────────────────────────────
@@ -44,8 +50,10 @@ describe("auth", () => {
4450

4551
if (!status.loggedIn) {
4652
throw new Error(
47-
"Not logged in to Booking.com. Run: browserkit login booking\n" +
48-
"Then restart the test server and re-run this suite."
53+
"Not logged in to Booking.com.\n" +
54+
"1. Run: browserkit login booking\n" +
55+
"2. Start the daemon: browserkit start --config browserkit.config.js\n" +
56+
"3. Re-run: pnpm test:integration"
4957
);
5058
}
5159

0 commit comments

Comments
 (0)