ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / mcp / test / plannerTools.js
Blame History Raw 146 lines
1
"use strict";
2
var __create = Object.create;
3
var __defProp = Object.defineProperty;
4
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
var __getOwnPropNames = Object.getOwnPropertyNames;
6
var __getProtoOf = Object.getPrototypeOf;
7
var __hasOwnProp = Object.prototype.hasOwnProperty;
8
var __export = (target, all) => {
9
for (var name in all)
10
__defProp(target, name, { get: all[name], enumerable: true });
11
};
12
var __copyProps = (to, from, except, desc) => {
13
if (from && typeof from === "object" || typeof from === "function") {
14
for (let key of __getOwnPropNames(from))
15
if (!__hasOwnProp.call(to, key) && key !== except)
16
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
}
18
return to;
19
};
20
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
// If the importer is in node compatibility mode or this is not an ESM
22
// file that has been converted to a CommonJS file using a Babel-
23
// compatible transform (i.e. "__esModule" has not been set), then set
24
// "default" to the CommonJS "module.exports" for node compatibility.
25
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
mod
27
));
28
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
var plannerTools_exports = {};
30
__export(plannerTools_exports, {
31
saveTestPlan: () => saveTestPlan,
32
setupPage: () => setupPage,
33
submitTestPlan: () => submitTestPlan
34
});
35
module.exports = __toCommonJS(plannerTools_exports);
36
var import_fs = __toESM(require("fs"));
37
var import_path = __toESM(require("path"));
38
var import_mcpBundle = require("playwright-core/lib/mcpBundle");
39
var import_testTool = require("./testTool");
40
const setupPage = (0, import_testTool.defineTestTool)({
41
schema: {
42
name: "planner_setup_page",
43
title: "Setup planner page",
44
description: "Setup the page for test planning",
45
inputSchema: import_mcpBundle.z.object({
46
project: import_mcpBundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
47
seedFile: import_mcpBundle.z.string().optional().describe('A seed file contains a single test that is used to setup the page for testing, for example: "tests/seed.spec.ts". If no seed file is provided, a default seed file is created.')
48
}),
49
type: "readOnly"
50
},
51
handle: async (context, params) => {
52
const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
53
const { output, status } = await context.runSeedTest(seed.file, seed.projectName);
54
return { content: [{ type: "text", text: output }], isError: status !== "paused" };
55
}
56
});
57
const planSchema = import_mcpBundle.z.object({
58
overview: import_mcpBundle.z.string().describe("A brief overview of the application to be tested"),
59
suites: import_mcpBundle.z.array(import_mcpBundle.z.object({
60
name: import_mcpBundle.z.string().describe("The name of the suite"),
61
seedFile: import_mcpBundle.z.string().describe("A seed file that was used to setup the page for testing."),
62
tests: import_mcpBundle.z.array(import_mcpBundle.z.object({
63
name: import_mcpBundle.z.string().describe("The name of the test"),
64
file: import_mcpBundle.z.string().describe('The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".'),
65
steps: import_mcpBundle.z.array(import_mcpBundle.z.object({
66
perform: import_mcpBundle.z.string().optional().describe(`Action to perform. For example: 'Click on the "Submit" button'.`),
67
expect: import_mcpBundle.z.string().array().describe(`Expected result of the action where appropriate. For example: 'The page should show the "Thank you for your submission" message'`)
68
}))
69
}))
70
}))
71
});
72
const submitTestPlan = (0, import_testTool.defineTestTool)({
73
schema: {
74
name: "planner_submit_plan",
75
title: "Submit test plan",
76
description: "Submit the test plan to the test planner",
77
inputSchema: planSchema,
78
type: "readOnly"
79
},
80
handle: async (context, params) => {
81
return {
82
content: [{
83
type: "text",
84
text: JSON.stringify(params, null, 2)
85
}]
86
};
87
}
88
});
89
const saveTestPlan = (0, import_testTool.defineTestTool)({
90
schema: {
91
name: "planner_save_plan",
92
title: "Save test plan as markdown file",
93
description: "Save the test plan as a markdown file",
94
inputSchema: planSchema.extend({
95
name: import_mcpBundle.z.string().describe('The name of the test plan, for example: "Test Plan".'),
96
fileName: import_mcpBundle.z.string().describe('The file to save the test plan to, for example: "spec/test.plan.md". Relative to the workspace root.')
97
}),
98
type: "readOnly"
99
},
100
handle: async (context, params) => {
101
const lines = [];
102
lines.push(`# ${params.name}`);
103
lines.push(``);
104
lines.push(`## Application Overview`);
105
lines.push(``);
106
lines.push(params.overview);
107
lines.push(``);
108
lines.push(`## Test Scenarios`);
109
for (let i = 0; i < params.suites.length; i++) {
110
lines.push(``);
111
const suite = params.suites[i];
112
lines.push(`### ${i + 1}. ${suite.name}`);
113
lines.push(``);
114
lines.push(`**Seed:** \`${suite.seedFile}\``);
115
for (let j = 0; j < suite.tests.length; j++) {
116
lines.push(``);
117
const test = suite.tests[j];
118
lines.push(`#### ${i + 1}.${j + 1}. ${test.name}`);
119
lines.push(``);
120
lines.push(`**File:** \`${test.file}\``);
121
lines.push(``);
122
lines.push(`**Steps:**`);
123
for (let k = 0; k < test.steps.length; k++) {
124
lines.push(` ${k + 1}. ${test.steps[k].perform ?? "-"}`);
125
for (const expect of test.steps[k].expect)
126
lines.push(` - expect: ${expect}`);
127
}
128
}
129
}
130
lines.push(``);
131
await import_fs.default.promises.writeFile(import_path.default.resolve(context.rootPath, params.fileName), lines.join("\n"));
132
return {
133
content: [{
134
type: "text",
135
text: `Test plan saved to ${params.fileName}`
136
}]
137
};
138
}
139
});
140
// Annotate the CommonJS export names for ESM import in node:
141
0 && (module.exports = {
142
saveTestPlan,
143
setupPage,
144
submitTestPlan
145
});
146

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button