mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
Run independent E2E cases concurrently and reuse MCP sessions
This commit is contained in:
1 parent
7c61c3e164
commit
9485a08056
6 files changed
+77
-100
No files matched your search
@@ -14,6 +14,8 @@ import {
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import { dashboardUrl, test } from "../test";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
test("Cloning a project preserves nested asset folders", async ({
|
||||
context,
|
||||
}) => {
|
||||
|
||||
@@ -18,6 +18,8 @@ import { test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
import { loadDevBuild } from "../db";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
type DataSourceRecord =
|
||||
| {
|
||||
id: string;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
||||
import { expect } from "@playwright/test";
|
||||
import { createContentModeProject } from "../fixtures/content-mode-suite";
|
||||
import { openProjectBuilder } from "../flows/builder";
|
||||
@@ -13,7 +13,6 @@ import { insertAuthorizationToken, loadDevBuild } from "../db";
|
||||
import { e2ePaidPlanName } from "../plans";
|
||||
import { dashboardUrl, test } from "../test";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const cliPath = fileURLToPath(
|
||||
new URL("../../../../packages/cli/local.js", import.meta.url)
|
||||
);
|
||||
@@ -47,6 +46,30 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
viewer: viewerDirectory,
|
||||
builder: builderDirectory,
|
||||
};
|
||||
const clients = new Map<keyof typeof directories, Client>();
|
||||
const connect = async (cwd: string, configDirectory: string) => {
|
||||
const client = new Client({
|
||||
name: "mcp-editor-pages-e2e",
|
||||
version: "1.0.0",
|
||||
});
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [cliPath, "mcp", "--project", fixture.projectId],
|
||||
cwd,
|
||||
env: {
|
||||
...process.env,
|
||||
WEBSTUDIO_CONFIG_DIR: configDirectory,
|
||||
} as Record<string, string>,
|
||||
stderr: "inherit",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport);
|
||||
} catch (error) {
|
||||
await client.close().catch(() => undefined);
|
||||
throw error;
|
||||
}
|
||||
return client;
|
||||
};
|
||||
const call = async (
|
||||
tool: string,
|
||||
input: object,
|
||||
@@ -55,28 +78,23 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
role = "editor",
|
||||
}: { fresh?: boolean; role?: keyof typeof directories } = {}
|
||||
) => {
|
||||
const args = [
|
||||
cliPath,
|
||||
"mcp",
|
||||
"single-op-call",
|
||||
tool,
|
||||
JSON.stringify(input),
|
||||
"--project",
|
||||
fixture.projectId,
|
||||
];
|
||||
const client = fresh
|
||||
? await connect(freshDirectory, directories[role])
|
||||
: (clients.get(role) ??
|
||||
(await connect(directories[role], directories[role])));
|
||||
if (fresh === false) {
|
||||
clients.set(role, client);
|
||||
}
|
||||
try {
|
||||
const { stdout } = await execFileAsync(process.execPath, args, {
|
||||
cwd: fresh ? freshDirectory : directories[role],
|
||||
timeout: 60_000,
|
||||
env: { ...process.env, WEBSTUDIO_CONFIG_DIR: directories[role] },
|
||||
const result = await client.callTool({
|
||||
name: tool,
|
||||
arguments: input as Record<string, unknown>,
|
||||
});
|
||||
return JSON.parse(stdout);
|
||||
} catch (error) {
|
||||
const stdout = (error as Error & { stdout?: string }).stdout;
|
||||
if (stdout === undefined) {
|
||||
throw error;
|
||||
return JSON.parse(JSON.stringify(result.structuredContent));
|
||||
} finally {
|
||||
if (fresh) {
|
||||
await client.close();
|
||||
}
|
||||
return JSON.parse(stdout);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -254,6 +272,7 @@ test("Editor MCP saves permitted pages, folders, and assets", async ({
|
||||
const builderPage = await call("get-page", { pageId }, { role: "builder" });
|
||||
expect(builderPage.data.meta.status).toBe("302");
|
||||
} finally {
|
||||
await Promise.all(Array.from(clients.values(), (client) => client.close()));
|
||||
await Promise.all([
|
||||
rm(directory, { recursive: true, force: true }),
|
||||
rm(freshDirectory, { recursive: true, force: true }),
|
||||
|
||||
@@ -22,6 +22,8 @@ import { e2eEmailPlanName } from "../plans";
|
||||
import { test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
type PersistedPages = {
|
||||
redirects?: Array<{
|
||||
old: string;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { Frame, Page } from "@playwright/test";
|
||||
import {
|
||||
getCanvasInstance,
|
||||
@@ -10,18 +11,12 @@ import {
|
||||
createSlotKeyboardProject,
|
||||
type SeededSlotKeyboardProject,
|
||||
} from "../fixtures/slot-keyboard-project";
|
||||
import { test, withBrowserContext } from "../test";
|
||||
import { test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
let fixture: SeededSlotKeyboardProject;
|
||||
let detachFixture: SeededSlotKeyboardProject;
|
||||
let navigatorFixture: SeededSlotKeyboardProject;
|
||||
let navigatorOutdentFixture: SeededSlotKeyboardProject;
|
||||
let topChildFixture: SeededSlotKeyboardProject;
|
||||
let bottomChildFixture: SeededSlotKeyboardProject;
|
||||
let navigatorTopChildFixture: SeededSlotKeyboardProject;
|
||||
let navigatorBottomChildFixture: SeededSlotKeyboardProject;
|
||||
let multiSelectFixture: SeededSlotKeyboardProject;
|
||||
|
||||
const slotASelector = getCanvasInstanceSelector([
|
||||
"slot-keyboard-slot-a",
|
||||
@@ -42,57 +37,12 @@ const expectCanvasInstanceVisible = async ({
|
||||
});
|
||||
};
|
||||
|
||||
test.beforeAll(async ({ browser }) => {
|
||||
await withBrowserContext(browser, async (context) => {
|
||||
fixture = await createSlotKeyboardProject({ context });
|
||||
detachFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-detach-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Detach E2E",
|
||||
builderToken: "slot-keyboard-detach-e2e-builder-token",
|
||||
});
|
||||
navigatorFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-navigator-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Navigator E2E",
|
||||
builderToken: "slot-keyboard-navigator-e2e-builder-token",
|
||||
});
|
||||
navigatorOutdentFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-navigator-outdent-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Navigator Outdent E2E",
|
||||
builderToken: "slot-keyboard-navigator-outdent-e2e-builder-token",
|
||||
});
|
||||
topChildFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-top-child-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Top Child E2E",
|
||||
builderToken: "slot-keyboard-top-child-e2e-builder-token",
|
||||
});
|
||||
bottomChildFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-bottom-child-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Bottom Child E2E",
|
||||
builderToken: "slot-keyboard-bottom-child-e2e-builder-token",
|
||||
});
|
||||
navigatorTopChildFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-navigator-top-child-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Navigator Top Child E2E",
|
||||
builderToken: "slot-keyboard-navigator-top-child-e2e-builder-token",
|
||||
});
|
||||
navigatorBottomChildFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-navigator-bottom-child-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Navigator Bottom Child E2E",
|
||||
builderToken: "slot-keyboard-navigator-bottom-child-e2e-builder-token",
|
||||
});
|
||||
multiSelectFixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: "slot-keyboard-navigator-multi-select-e2e@webstudio.test",
|
||||
title: "Slot Keyboard Multi Select E2E",
|
||||
builderToken: "slot-keyboard-navigator-multi-select-e2e-builder-token",
|
||||
});
|
||||
test.beforeEach(async ({ context }) => {
|
||||
const id = randomUUID();
|
||||
fixture = await createSlotKeyboardProject({
|
||||
context,
|
||||
email: `slot-keyboard-${id}@webstudio.test`,
|
||||
builderToken: `slot-keyboard-${id}-builder-token`,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -238,8 +188,8 @@ test("Keyboard shortcut keeps Navigator arrows working after outdenting a row",
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: navigatorOutdentFixture.projectId,
|
||||
authToken: navigatorOutdentFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -288,8 +238,8 @@ test("Shift+ArrowDown in Navigator selects exactly one additional row", async ({
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: multiSelectFixture.projectId,
|
||||
authToken: multiSelectFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -334,8 +284,8 @@ test("Control/Command+A after canvas selection selects sibling rows", async ({
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: multiSelectFixture.projectId,
|
||||
authToken: multiSelectFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -376,8 +326,8 @@ test("Keyboard shortcut moves a direct shared slot child out of all slot occurre
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: detachFixture.projectId,
|
||||
authToken: detachFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -434,8 +384,8 @@ test("Keyboard shortcut moves the first shared slot child above all slot occurre
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: navigatorTopChildFixture.projectId,
|
||||
authToken: navigatorTopChildFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -509,8 +459,8 @@ test("Keyboard shortcut moves the last shared slot child below all slot occurren
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: navigatorBottomChildFixture.projectId,
|
||||
authToken: navigatorBottomChildFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -584,8 +534,8 @@ test("Keyboard shortcut reorders a shared slot child from navigator focus", asyn
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: navigatorFixture.projectId,
|
||||
authToken: navigatorFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -648,8 +598,8 @@ test("Keyboard shortcut moves the first shared slot child above all slot occurre
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: topChildFixture.projectId,
|
||||
authToken: topChildFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -721,8 +671,8 @@ test("Keyboard shortcut moves the last shared slot child below all slot occurren
|
||||
async () => {
|
||||
return await openProjectBuilder({
|
||||
page,
|
||||
projectId: bottomChildFixture.projectId,
|
||||
authToken: bottomChildFixture.builderToken,
|
||||
projectId: fixture.projectId,
|
||||
authToken: fixture.builderToken,
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -14,6 +14,8 @@ import { test } from "../test";
|
||||
import { measure } from "../perf";
|
||||
import { loadDevBuild } from "../db";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
const createStylePanelRuntimeProject = async (
|
||||
context: BrowserContext,
|
||||
name: string
|
||||
|
||||
Reference in new issue
Block a user