Skip to content

Commit 903b60b

Browse files
author
rocketraccoon
committed
feat(mcp-tools): add run tests using testplane
1 parent 9842031 commit 903b60b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { openNewTab } from "./open-new-tab.js";
1111
import { closeTab } from "./close-tab.js";
1212
import { waitForElement } from "./wait-for-element.js";
1313
import { attachToBrowser } from "./attach-to-browser.js";
14+
import { runTests } from "./run-tests.js";
1415

1516
export const tools = [
1617
navigate,
@@ -25,4 +26,5 @@ export const tools = [
2526
closeTab,
2627
waitForElement,
2728
attachToBrowser,
29+
runTests,
2830
] as const satisfies ToolDefinition<any>[]; // eslint-disable-line @typescript-eslint/no-explicit-any

src/tools/run-tests.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ToolDefinition } from "../types.js";
2+
import { ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
3+
import { createSimpleResponse, createErrorResponse } from "../responses/index.js";
4+
import { execSync } from "child_process";
5+
import { z } from "zod";
6+
7+
const runTestsSchema = {
8+
projectDir: z.string().describe("Project directory"),
9+
keepBrowser: z.boolean().describe("Save browser after run").optional(),
10+
};
11+
12+
const runTestsCb: ToolCallback<typeof runTestsSchema> = async ({ projectDir, keepBrowser = false }) => {
13+
try {
14+
const result = execSync(`cd ${projectDir} && npx testplane ${keepBrowser ? "--keep-browser" : ""}`);
15+
16+
return createSimpleResponse(`Successfully run tests:\n${result}`);
17+
} catch (error) {
18+
console.error("Error run tests:", error);
19+
return createErrorResponse("Error run tests", error instanceof Error ? error : undefined);
20+
}
21+
};
22+
23+
export const runTests: ToolDefinition<typeof runTestsSchema> = {
24+
name: "runTests",
25+
description: "Run tests",
26+
schema: runTestsSchema,
27+
cb: runTestsCb,
28+
};

0 commit comments

Comments
 (0)