Skip to content

Commit 20ef214

Browse files
ochafikclaude
andcommitted
Add interaction tests for basic server apps
Test that clicking buttons in the MCP App triggers the corresponding host callbacks: - Send Message → host logs "Message from MCP App" - Send Log → host logs "Log message from MCP App" - Open Link → host logs "Open link request" Tests both React and Vanilla JS implementations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9aa7727 commit 20ef214

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

tests/e2e/servers.spec.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
import { test, expect, type Page } from "@playwright/test";
1+
import { test, expect, type Page, type ConsoleMessage } from "@playwright/test";
2+
3+
/**
4+
* Helper to get the app frame locator (nested: sandbox > app)
5+
*/
6+
function getAppFrame(page: Page) {
7+
return page.frameLocator("iframe").first().frameLocator("iframe").first();
8+
}
9+
10+
/**
11+
* Collect console messages with [HOST] prefix
12+
*/
13+
function captureHostLogs(page: Page): string[] {
14+
const logs: string[] = [];
15+
page.on("console", (msg: ConsoleMessage) => {
16+
const text = msg.text();
17+
if (text.includes("[HOST]")) {
18+
logs.push(text);
19+
}
20+
});
21+
return logs;
22+
}
223

324
// Server configurations
425
const SERVERS = [
@@ -67,3 +88,53 @@ SERVERS.forEach((server) => {
6788
});
6889
});
6990
});
91+
92+
// Interaction tests for basic servers (React and Vanilla JS have identical UIs)
93+
const BASIC_SERVERS = SERVERS.filter(
94+
(s) => s.key === "basic-react" || s.key === "basic-vanillajs",
95+
);
96+
97+
BASIC_SERVERS.forEach((server) => {
98+
test.describe(`${server.name} - Interactions`, () => {
99+
test("Send Message button triggers host callback", async ({ page }) => {
100+
const logs = captureHostLogs(page);
101+
await loadServer(page, server.index);
102+
103+
const appFrame = getAppFrame(page);
104+
await appFrame.locator('button:has-text("Send Message")').click();
105+
106+
// Wait for the async message to be processed
107+
await page.waitForTimeout(500);
108+
109+
expect(logs.some((log) => log.includes("Message from MCP App"))).toBe(
110+
true,
111+
);
112+
});
113+
114+
test("Send Log button triggers host callback", async ({ page }) => {
115+
const logs = captureHostLogs(page);
116+
await loadServer(page, server.index);
117+
118+
const appFrame = getAppFrame(page);
119+
await appFrame.locator('button:has-text("Send Log")').click();
120+
121+
await page.waitForTimeout(500);
122+
123+
expect(logs.some((log) => log.includes("Log message from MCP App"))).toBe(
124+
true,
125+
);
126+
});
127+
128+
test("Open Link button triggers host callback", async ({ page }) => {
129+
const logs = captureHostLogs(page);
130+
await loadServer(page, server.index);
131+
132+
const appFrame = getAppFrame(page);
133+
await appFrame.locator('button:has-text("Open Link")').click();
134+
135+
await page.waitForTimeout(500);
136+
137+
expect(logs.some((log) => log.includes("Open link request"))).toBe(true);
138+
});
139+
});
140+
});

0 commit comments

Comments
 (0)