rae-playwright-mcp 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -21
- package/cli.js +7 -3
- package/index.js +1 -1
- package/lib/common/config.js +282 -0
- package/lib/common/config.js.map +7 -0
- package/lib/common/configLoader.js +345 -0
- package/lib/common/configLoader.js.map +7 -0
- package/lib/common/esmLoaderHost.js +105 -0
- package/lib/common/esmLoaderHost.js.map +7 -0
- package/lib/common/expectBundle.js +44 -0
- package/lib/common/expectBundle.js.map +7 -0
- package/lib/common/expectBundleImpl.js +15781 -0
- package/lib/common/expectBundleImpl.js.map +7 -0
- package/lib/common/fixtures.js +303 -0
- package/lib/common/fixtures.js.map +7 -0
- package/lib/common/globals.js +59 -0
- package/lib/common/globals.js.map +7 -0
- package/lib/common/ipc.js +61 -0
- package/lib/common/ipc.js.map +7 -0
- package/lib/common/poolBuilder.js +86 -0
- package/lib/common/poolBuilder.js.map +7 -0
- package/lib/common/process.js +133 -0
- package/lib/common/process.js.map +7 -0
- package/lib/common/suiteUtils.js +141 -0
- package/lib/common/suiteUtils.js.map +7 -0
- package/lib/common/test.js +323 -0
- package/lib/common/test.js.map +7 -0
- package/lib/common/testLoader.js +102 -0
- package/lib/common/testLoader.js.map +7 -0
- package/lib/common/testType.js +299 -0
- package/lib/common/testType.js.map +7 -0
- package/lib/common/validators.js +69 -0
- package/lib/common/validators.js.map +7 -0
- package/lib/mcp/browser/actions.d.js +17 -0
- package/lib/mcp/browser/actions.d.js.map +7 -0
- package/lib/mcp/browser/browserContextFactory.js +343 -0
- package/lib/mcp/browser/browserContextFactory.js.map +7 -0
- package/lib/mcp/browser/browserServerBackend.js +78 -0
- package/lib/mcp/browser/browserServerBackend.js.map +7 -0
- package/lib/mcp/browser/config.js +421 -0
- package/lib/mcp/browser/config.js.map +7 -0
- package/lib/mcp/browser/context.js +287 -0
- package/lib/mcp/browser/context.js.map +7 -0
- package/lib/mcp/browser/response.js +353 -0
- package/lib/mcp/browser/response.js.map +7 -0
- package/lib/mcp/browser/sessionLog.js +161 -0
- package/lib/mcp/browser/sessionLog.js.map +7 -0
- package/lib/mcp/browser/tab.js +329 -0
- package/lib/mcp/browser/tab.js.map +7 -0
- package/lib/mcp/browser/tools/common.js +64 -0
- package/lib/mcp/browser/tools/common.js.map +7 -0
- package/lib/mcp/browser/tools/console.js +45 -0
- package/lib/mcp/browser/tools/console.js.map +7 -0
- package/lib/mcp/browser/tools/dialogs.js +61 -0
- package/lib/mcp/browser/tools/dialogs.js.map +7 -0
- package/lib/mcp/browser/tools/evaluate.js +60 -0
- package/lib/mcp/browser/tools/evaluate.js.map +7 -0
- package/lib/mcp/browser/tools/files.js +59 -0
- package/lib/mcp/browser/tools/files.js.map +7 -0
- package/lib/mcp/browser/tools/form.js +64 -0
- package/lib/mcp/browser/tools/form.js.map +7 -0
- package/lib/mcp/browser/tools/install.js +70 -0
- package/lib/mcp/browser/tools/install.js.map +7 -0
- package/lib/mcp/browser/tools/keyboard.js +85 -0
- package/lib/mcp/browser/tools/keyboard.js.map +7 -0
- package/lib/mcp/browser/tools/mouse.js +108 -0
- package/lib/mcp/browser/tools/mouse.js.map +7 -0
- package/lib/mcp/browser/tools/navigate.js +63 -0
- package/lib/mcp/browser/tools/navigate.js.map +7 -0
- package/lib/mcp/browser/tools/network.js +61 -0
- package/lib/mcp/browser/tools/network.js.map +7 -0
- package/lib/mcp/browser/tools/pdf.js +49 -0
- package/lib/mcp/browser/tools/pdf.js.map +7 -0
- package/lib/mcp/browser/tools/runCode.js +78 -0
- package/lib/mcp/browser/tools/runCode.js.map +7 -0
- package/lib/mcp/browser/tools/screenshot.js +106 -0
- package/lib/mcp/browser/tools/screenshot.js.map +7 -0
- package/lib/mcp/browser/tools/snapshot.js +192 -0
- package/lib/mcp/browser/tools/snapshot.js.map +7 -0
- package/lib/mcp/browser/tools/tabs.js +68 -0
- package/lib/mcp/browser/tools/tabs.js.map +7 -0
- package/lib/mcp/browser/tools/tool.js +51 -0
- package/lib/mcp/browser/tools/tool.js.map +7 -0
- package/lib/mcp/browser/tools/tracing.js +76 -0
- package/lib/mcp/browser/tools/tracing.js.map +7 -0
- package/lib/mcp/browser/tools/utils.js +95 -0
- package/lib/mcp/browser/tools/utils.js.map +7 -0
- package/lib/mcp/browser/tools/verify.js +144 -0
- package/lib/mcp/browser/tools/verify.js.map +7 -0
- package/lib/mcp/browser/tools/wait.js +64 -0
- package/lib/mcp/browser/tools/wait.js.map +7 -0
- package/lib/mcp/browser/tools.js +83 -0
- package/lib/mcp/browser/tools.js.map +7 -0
- package/lib/mcp/browser/watchdog.js +45 -0
- package/lib/mcp/browser/watchdog.js.map +7 -0
- package/lib/mcp/config.d.js +17 -0
- package/lib/mcp/config.d.js.map +7 -0
- package/lib/mcp/config.d.ts +197 -0
- package/lib/mcp/extension/cdpRelay.js +352 -0
- package/lib/mcp/extension/cdpRelay.js.map +7 -0
- package/lib/mcp/extension/extensionContextFactory.js +77 -0
- package/lib/mcp/extension/extensionContextFactory.js.map +7 -0
- package/lib/mcp/extension/protocol.js +29 -0
- package/lib/mcp/extension/protocol.js.map +7 -0
- package/lib/mcp/index.js +62 -0
- package/lib/mcp/index.js.map +7 -0
- package/lib/mcp/log.js +36 -0
- package/lib/mcp/log.js.map +7 -0
- package/lib/mcp/program.js +94 -0
- package/lib/mcp/program.js.map +7 -0
- package/lib/mcp/sdk/exports.js +29 -0
- package/lib/mcp/sdk/exports.js.map +7 -0
- package/lib/mcp/sdk/http.js +153 -0
- package/lib/mcp/sdk/http.js.map +7 -0
- package/lib/mcp/sdk/inProcessTransport.js +72 -0
- package/lib/mcp/sdk/inProcessTransport.js.map +7 -0
- package/lib/mcp/sdk/server.js +208 -0
- package/lib/mcp/sdk/server.js.map +7 -0
- package/lib/mcp/sdk/tool.js +48 -0
- package/lib/mcp/sdk/tool.js.map +7 -0
- package/lib/mcp/test/browserBackend.js +99 -0
- package/lib/mcp/test/browserBackend.js.map +7 -0
- package/lib/mcp/test/generatorTools.js +123 -0
- package/lib/mcp/test/generatorTools.js.map +7 -0
- package/lib/mcp/test/plannerTools.js +145 -0
- package/lib/mcp/test/plannerTools.js.map +7 -0
- package/lib/mcp/test/seed.js +83 -0
- package/lib/mcp/test/seed.js.map +7 -0
- package/lib/mcp/test/streams.js +45 -0
- package/lib/mcp/test/streams.js.map +7 -0
- package/lib/mcp/test/testBackend.js +100 -0
- package/lib/mcp/test/testBackend.js.map +7 -0
- package/lib/mcp/test/testContext.js +280 -0
- package/lib/mcp/test/testContext.js.map +7 -0
- package/lib/mcp/test/testTool.js +31 -0
- package/lib/mcp/test/testTool.js.map +7 -0
- package/lib/mcp/test/testTools.js +109 -0
- package/lib/mcp/test/testTools.js.map +7 -0
- package/lib/third_party/pirates.js +63 -0
- package/lib/third_party/pirates.js.map +7 -0
- package/lib/third_party/tsconfig-loader.js +104 -0
- package/lib/third_party/tsconfig-loader.js.map +7 -0
- package/lib/transform/babelBundle.js +44 -0
- package/lib/transform/babelBundle.js.map +7 -0
- package/lib/transform/babelBundleImpl.js +68726 -0
- package/lib/transform/babelBundleImpl.js.map +7 -0
- package/lib/transform/babelHighlightUtils.js +64 -0
- package/lib/transform/babelHighlightUtils.js.map +7 -0
- package/lib/transform/compilationCache.js +273 -0
- package/lib/transform/compilationCache.js.map +7 -0
- package/lib/transform/esmLoader.js +104 -0
- package/lib/transform/esmLoader.js.map +7 -0
- package/lib/transform/portTransport.js +68 -0
- package/lib/transform/portTransport.js.map +7 -0
- package/lib/transform/transform.js +297 -0
- package/lib/transform/transform.js.map +7 -0
- package/lib/util.js +404 -0
- package/lib/utilsBundle.js +44 -0
- package/lib/utilsBundleImpl.js +13122 -0
- package/package.json +4 -3
|
@@ -0,0 +1,280 @@
|
|
|
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 testContext_exports = {};
|
|
30
|
+
__export(testContext_exports, {
|
|
31
|
+
GeneratorJournal: () => GeneratorJournal,
|
|
32
|
+
TestContext: () => TestContext,
|
|
33
|
+
createScreen: () => createScreen
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(testContext_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_os = __toESM(require("os"));
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils = require("playwright-core/lib/utils");
|
|
40
|
+
var import_base = require("../../reporters/base");
|
|
41
|
+
var import_list = __toESM(require("../../reporters/list"));
|
|
42
|
+
var import_streams = require("./streams");
|
|
43
|
+
var import_util = require("../../util");
|
|
44
|
+
var import_testRunner = require("../../runner/testRunner");
|
|
45
|
+
var import_seed = require("./seed");
|
|
46
|
+
var import_exports = require("../sdk/exports");
|
|
47
|
+
var import_configLoader = require("../../common/configLoader");
|
|
48
|
+
var import_response = require("../browser/response");
|
|
49
|
+
var import_log = require("../log");
|
|
50
|
+
class GeneratorJournal {
|
|
51
|
+
constructor(rootPath, plan, seed) {
|
|
52
|
+
this._rootPath = rootPath;
|
|
53
|
+
this._plan = plan;
|
|
54
|
+
this._seed = seed;
|
|
55
|
+
this._steps = [];
|
|
56
|
+
}
|
|
57
|
+
logStep(title, code) {
|
|
58
|
+
if (title)
|
|
59
|
+
this._steps.push({ title, code });
|
|
60
|
+
}
|
|
61
|
+
journal() {
|
|
62
|
+
const result = [];
|
|
63
|
+
result.push(`# Plan`);
|
|
64
|
+
result.push(this._plan);
|
|
65
|
+
result.push(`# Seed file: ${(0, import_utils.toPosixPath)(import_path.default.relative(this._rootPath, this._seed.file))}`);
|
|
66
|
+
result.push("```ts");
|
|
67
|
+
result.push(this._seed.content);
|
|
68
|
+
result.push("```");
|
|
69
|
+
result.push(`# Steps`);
|
|
70
|
+
result.push(this._steps.map((step) => `### ${step.title}
|
|
71
|
+
\`\`\`ts
|
|
72
|
+
${step.code}
|
|
73
|
+
\`\`\``).join("\n\n"));
|
|
74
|
+
result.push(bestPracticesMarkdown);
|
|
75
|
+
return result.join("\n\n");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class TestContext {
|
|
79
|
+
constructor(clientInfo, configPath, options) {
|
|
80
|
+
this._clientInfo = clientInfo;
|
|
81
|
+
const rootPath = (0, import_exports.firstRootPath)(clientInfo);
|
|
82
|
+
this._configLocation = (0, import_configLoader.resolveConfigLocation)(configPath || rootPath);
|
|
83
|
+
this.rootPath = rootPath || this._configLocation.configDir;
|
|
84
|
+
if (options?.headless !== void 0)
|
|
85
|
+
this.computedHeaded = !options.headless;
|
|
86
|
+
else
|
|
87
|
+
this.computedHeaded = !process.env.CI && !(import_os.default.platform() === "linux" && !process.env.DISPLAY);
|
|
88
|
+
}
|
|
89
|
+
existingTestRunner() {
|
|
90
|
+
return this._testRunnerAndScreen?.testRunner;
|
|
91
|
+
}
|
|
92
|
+
async _cleanupTestRunner() {
|
|
93
|
+
if (!this._testRunnerAndScreen)
|
|
94
|
+
return;
|
|
95
|
+
await this._testRunnerAndScreen.testRunner.stopTests();
|
|
96
|
+
this._testRunnerAndScreen.claimStdio();
|
|
97
|
+
try {
|
|
98
|
+
await this._testRunnerAndScreen.testRunner.runGlobalTeardown();
|
|
99
|
+
} finally {
|
|
100
|
+
this._testRunnerAndScreen.releaseStdio();
|
|
101
|
+
this._testRunnerAndScreen = void 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async createTestRunner() {
|
|
105
|
+
await this._cleanupTestRunner();
|
|
106
|
+
const testRunner = new import_testRunner.TestRunner(this._configLocation, {});
|
|
107
|
+
await testRunner.initialize({});
|
|
108
|
+
const testPaused = new import_utils.ManualPromise();
|
|
109
|
+
const testRunnerAndScreen = {
|
|
110
|
+
...createScreen(),
|
|
111
|
+
testRunner,
|
|
112
|
+
waitForTestPaused: () => testPaused
|
|
113
|
+
};
|
|
114
|
+
this._testRunnerAndScreen = testRunnerAndScreen;
|
|
115
|
+
testRunner.on(import_testRunner.TestRunnerEvent.TestPaused, (params) => {
|
|
116
|
+
testRunnerAndScreen.sendMessageToPausedTest = params.sendMessage;
|
|
117
|
+
testPaused.resolve();
|
|
118
|
+
});
|
|
119
|
+
return testRunnerAndScreen;
|
|
120
|
+
}
|
|
121
|
+
async getOrCreateSeedFile(seedFile, projectName) {
|
|
122
|
+
const configDir = this._configLocation.configDir;
|
|
123
|
+
const { testRunner } = await this.createTestRunner();
|
|
124
|
+
const config = await testRunner.loadConfig();
|
|
125
|
+
const project = (0, import_seed.seedProject)(config, projectName);
|
|
126
|
+
if (!seedFile) {
|
|
127
|
+
seedFile = await (0, import_seed.ensureSeedFile)(project);
|
|
128
|
+
} else {
|
|
129
|
+
const candidateFiles = [];
|
|
130
|
+
const testDir = project.project.testDir;
|
|
131
|
+
candidateFiles.push(import_path.default.resolve(testDir, seedFile));
|
|
132
|
+
candidateFiles.push(import_path.default.resolve(configDir, seedFile));
|
|
133
|
+
candidateFiles.push(import_path.default.resolve(this.rootPath, seedFile));
|
|
134
|
+
let resolvedSeedFile;
|
|
135
|
+
for (const candidateFile of candidateFiles) {
|
|
136
|
+
if (await (0, import_util.fileExistsAsync)(candidateFile)) {
|
|
137
|
+
resolvedSeedFile = candidateFile;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!resolvedSeedFile)
|
|
142
|
+
throw new Error("seed test not found.");
|
|
143
|
+
seedFile = resolvedSeedFile;
|
|
144
|
+
}
|
|
145
|
+
const seedFileContent = await import_fs.default.promises.readFile(seedFile, "utf8");
|
|
146
|
+
return {
|
|
147
|
+
file: seedFile,
|
|
148
|
+
content: seedFileContent,
|
|
149
|
+
projectName: project.project.name
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async runSeedTest(seedFile, projectName) {
|
|
153
|
+
const result = await this.runTestsWithGlobalSetupAndPossiblePause({
|
|
154
|
+
headed: this.computedHeaded,
|
|
155
|
+
locations: ["/" + (0, import_utils.escapeRegExp)(seedFile) + "/"],
|
|
156
|
+
projects: [projectName],
|
|
157
|
+
timeout: 0,
|
|
158
|
+
workers: 1,
|
|
159
|
+
pauseAtEnd: true,
|
|
160
|
+
disableConfigReporters: true,
|
|
161
|
+
failOnLoadErrors: true
|
|
162
|
+
});
|
|
163
|
+
if (result.status === "passed")
|
|
164
|
+
result.output += "\nError: seed test not found.";
|
|
165
|
+
else if (result.status !== "paused")
|
|
166
|
+
result.output += "\nError while running the seed test.";
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
async runTestsWithGlobalSetupAndPossiblePause(params) {
|
|
170
|
+
const configDir = this._configLocation.configDir;
|
|
171
|
+
const testRunnerAndScreen = await this.createTestRunner();
|
|
172
|
+
const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;
|
|
173
|
+
claimStdio();
|
|
174
|
+
try {
|
|
175
|
+
const setupReporter = new import_list.default({ configDir, screen, includeTestId: true });
|
|
176
|
+
const { status: status2 } = await testRunner.runGlobalSetup([setupReporter]);
|
|
177
|
+
if (status2 !== "passed")
|
|
178
|
+
return { output: testRunnerAndScreen.output.join("\n"), status: status2 };
|
|
179
|
+
} finally {
|
|
180
|
+
releaseStdio();
|
|
181
|
+
}
|
|
182
|
+
let status = "passed";
|
|
183
|
+
const cleanup = async () => {
|
|
184
|
+
claimStdio();
|
|
185
|
+
try {
|
|
186
|
+
const result = await testRunner.runGlobalTeardown();
|
|
187
|
+
if (status === "passed")
|
|
188
|
+
status = result.status;
|
|
189
|
+
} finally {
|
|
190
|
+
releaseStdio();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
try {
|
|
194
|
+
const reporter = new import_list.default({ configDir, screen, includeTestId: true });
|
|
195
|
+
status = await Promise.race([
|
|
196
|
+
testRunner.runTests(reporter, params).then((result) => result.status),
|
|
197
|
+
testRunnerAndScreen.waitForTestPaused().then(() => "paused")
|
|
198
|
+
]);
|
|
199
|
+
if (status === "paused") {
|
|
200
|
+
const response = await testRunnerAndScreen.sendMessageToPausedTest({ request: { initialize: { clientInfo: this._clientInfo } } });
|
|
201
|
+
if (response.error)
|
|
202
|
+
throw new Error(response.error.message);
|
|
203
|
+
testRunnerAndScreen.output.push(response.response.initialize.pausedMessage);
|
|
204
|
+
return { output: testRunnerAndScreen.output.join("\n"), status };
|
|
205
|
+
}
|
|
206
|
+
} catch (e) {
|
|
207
|
+
status = "failed";
|
|
208
|
+
testRunnerAndScreen.output.push(String(e));
|
|
209
|
+
await cleanup();
|
|
210
|
+
return { output: testRunnerAndScreen.output.join("\n"), status };
|
|
211
|
+
}
|
|
212
|
+
await cleanup();
|
|
213
|
+
return { output: testRunnerAndScreen.output.join("\n"), status };
|
|
214
|
+
}
|
|
215
|
+
async close() {
|
|
216
|
+
await this._cleanupTestRunner().catch(import_log.logUnhandledError);
|
|
217
|
+
}
|
|
218
|
+
async sendMessageToPausedTest(request) {
|
|
219
|
+
const sendMessage = this._testRunnerAndScreen?.sendMessageToPausedTest;
|
|
220
|
+
if (!sendMessage)
|
|
221
|
+
throw new Error("Must setup test before interacting with the page");
|
|
222
|
+
const result = await sendMessage({ request });
|
|
223
|
+
if (result.error)
|
|
224
|
+
throw new Error(result.error.message);
|
|
225
|
+
if (typeof request?.callTool?.arguments?.["intent"] === "string") {
|
|
226
|
+
const response = (0, import_response.parseResponse)(result.response.callTool);
|
|
227
|
+
if (response && !response.isError && response.code)
|
|
228
|
+
this.generatorJournal?.logStep(request.callTool.arguments["intent"], response.code);
|
|
229
|
+
}
|
|
230
|
+
return result.response;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function createScreen() {
|
|
234
|
+
const output = [];
|
|
235
|
+
const stdout = new import_streams.StringWriteStream(output, "stdout");
|
|
236
|
+
const stderr = new import_streams.StringWriteStream(output, "stderr");
|
|
237
|
+
const screen = {
|
|
238
|
+
...import_base.terminalScreen,
|
|
239
|
+
isTTY: false,
|
|
240
|
+
colors: import_utils.noColors,
|
|
241
|
+
stdout,
|
|
242
|
+
stderr
|
|
243
|
+
};
|
|
244
|
+
const originalStdoutWrite = process.stdout.write;
|
|
245
|
+
const originalStderrWrite = process.stderr.write;
|
|
246
|
+
const claimStdio = () => {
|
|
247
|
+
process.stdout.write = (chunk) => {
|
|
248
|
+
stdout.write(chunk);
|
|
249
|
+
return true;
|
|
250
|
+
};
|
|
251
|
+
process.stderr.write = (chunk) => {
|
|
252
|
+
stderr.write(chunk);
|
|
253
|
+
return true;
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
const releaseStdio = () => {
|
|
257
|
+
process.stdout.write = originalStdoutWrite;
|
|
258
|
+
process.stderr.write = originalStderrWrite;
|
|
259
|
+
};
|
|
260
|
+
return { screen, claimStdio, releaseStdio, output };
|
|
261
|
+
}
|
|
262
|
+
const bestPracticesMarkdown = `
|
|
263
|
+
# Best practices
|
|
264
|
+
- Do not improvise, do not add directives that were not asked for
|
|
265
|
+
- Use clear, descriptive assertions to validate the expected behavior
|
|
266
|
+
- Use reliable locators from this log
|
|
267
|
+
- Use local variables for locators that are used multiple times
|
|
268
|
+
- Use Playwright waiting assertions and best practices from this log
|
|
269
|
+
- NEVER! use page.waitForLoadState()
|
|
270
|
+
- NEVER! use page.waitForNavigation()
|
|
271
|
+
- NEVER! use page.waitForTimeout()
|
|
272
|
+
- NEVER! use page.evaluate()
|
|
273
|
+
`;
|
|
274
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
275
|
+
0 && (module.exports = {
|
|
276
|
+
GeneratorJournal,
|
|
277
|
+
TestContext,
|
|
278
|
+
createScreen
|
|
279
|
+
});
|
|
280
|
+
//# sourceMappingURL=testContext.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mcp/test/testContext.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs';\nimport os from 'os';\nimport path from 'path';\n\nimport { noColors, escapeRegExp, ManualPromise, toPosixPath } from 'playwright-core/lib/utils';\n\nimport { terminalScreen } from '../../reporters/base';\nimport ListReporter from '../../reporters/list';\nimport { StringWriteStream } from './streams';\nimport { fileExistsAsync } from '../../util';\nimport { TestRunner, TestRunnerEvent } from '../../runner/testRunner';\nimport { ensureSeedFile, seedProject } from './seed';\nimport { firstRootPath } from '../sdk/exports';\nimport { resolveConfigLocation } from '../../common/configLoader';\nimport { parseResponse } from '../browser/response';\nimport { logUnhandledError } from '../log';\n\nimport type { TerminalScreen } from '../../reporters/base';\nimport type { FullResultStatus, RunTestsParams } from '../../runner/testRunner';\nimport type { ConfigLocation } from '../../common/config';\nimport type { ClientInfo } from '../sdk/exports';\nimport type { BrowserMCPRequest, BrowserMCPResponse } from './browserBackend';\n\nexport type SeedFile = {\n file: string;\n content: string;\n};\n\nexport class GeneratorJournal {\n private _rootPath: string;\n private _plan: string;\n private _seed: SeedFile;\n private _steps: { title: string, code: string }[];\n\n constructor(rootPath: string, plan: string, seed: SeedFile) {\n this._rootPath = rootPath;\n this._plan = plan;\n this._seed = seed;\n this._steps = [];\n }\n\n logStep(title: string | undefined, code: string) {\n if (title)\n this._steps.push({ title, code });\n }\n\n journal() {\n const result: string[] = [];\n result.push(`# Plan`);\n result.push(this._plan);\n result.push(`# Seed file: ${toPosixPath(path.relative(this._rootPath, this._seed.file))}`);\n result.push('```ts');\n result.push(this._seed.content);\n result.push('```');\n result.push(`# Steps`);\n result.push(this._steps.map(step => `### ${step.title}\n\\`\\`\\`ts\n${step.code}\n\\`\\`\\``).join('\\n\\n'));\n result.push(bestPracticesMarkdown);\n return result.join('\\n\\n');\n }\n}\n\ntype TestRunnerAndScreen = {\n testRunner: TestRunner;\n screen: TerminalScreen;\n claimStdio: () => void;\n releaseStdio: () => void;\n output: string[];\n waitForTestPaused: () => Promise<void>;\n sendMessageToPausedTest?: (params: { request: BrowserMCPRequest }) => Promise<{ response: BrowserMCPResponse, error?: any }>;\n};\n\nexport class TestContext {\n private _clientInfo: ClientInfo;\n private _testRunnerAndScreen: TestRunnerAndScreen | undefined;\n readonly computedHeaded: boolean;\n private readonly _configLocation: ConfigLocation;\n readonly rootPath: string;\n generatorJournal: GeneratorJournal | undefined;\n\n constructor(clientInfo: ClientInfo, configPath: string | undefined, options?: { muteConsole?: boolean, headless?: boolean }) {\n this._clientInfo = clientInfo;\n\n const rootPath = firstRootPath(clientInfo);\n this._configLocation = resolveConfigLocation(configPath || rootPath);\n this.rootPath = rootPath || this._configLocation.configDir;\n\n if (options?.headless !== undefined)\n this.computedHeaded = !options.headless;\n else\n this.computedHeaded = !process.env.CI && !(os.platform() === 'linux' && !process.env.DISPLAY);\n }\n\n existingTestRunner(): TestRunner | undefined {\n return this._testRunnerAndScreen?.testRunner;\n }\n\n private async _cleanupTestRunner() {\n if (!this._testRunnerAndScreen)\n return;\n await this._testRunnerAndScreen.testRunner.stopTests();\n this._testRunnerAndScreen.claimStdio();\n try {\n await this._testRunnerAndScreen.testRunner.runGlobalTeardown();\n } finally {\n this._testRunnerAndScreen.releaseStdio();\n this._testRunnerAndScreen = undefined;\n }\n }\n\n async createTestRunner() {\n await this._cleanupTestRunner();\n\n const testRunner = new TestRunner(this._configLocation, {});\n await testRunner.initialize({});\n const testPaused = new ManualPromise<void>();\n const testRunnerAndScreen: TestRunnerAndScreen = {\n ...createScreen(),\n testRunner,\n waitForTestPaused: () => testPaused,\n };\n this._testRunnerAndScreen = testRunnerAndScreen;\n\n testRunner.on(TestRunnerEvent.TestPaused, params => {\n testRunnerAndScreen.sendMessageToPausedTest = params.sendMessage;\n testPaused.resolve();\n });\n return testRunnerAndScreen;\n }\n\n async getOrCreateSeedFile(seedFile: string | undefined, projectName: string | undefined) {\n const configDir = this._configLocation.configDir;\n const { testRunner } = await this.createTestRunner();\n const config = await testRunner.loadConfig();\n const project = seedProject(config, projectName);\n\n if (!seedFile) {\n seedFile = await ensureSeedFile(project);\n } else {\n const candidateFiles: string[] = [];\n const testDir = project.project.testDir;\n candidateFiles.push(path.resolve(testDir, seedFile));\n candidateFiles.push(path.resolve(configDir, seedFile));\n candidateFiles.push(path.resolve(this.rootPath, seedFile));\n let resolvedSeedFile: string | undefined;\n for (const candidateFile of candidateFiles) {\n if (await fileExistsAsync(candidateFile)) {\n resolvedSeedFile = candidateFile;\n break;\n }\n }\n if (!resolvedSeedFile)\n throw new Error('seed test not found.');\n seedFile = resolvedSeedFile;\n }\n\n const seedFileContent = await fs.promises.readFile(seedFile, 'utf8');\n return {\n file: seedFile,\n content: seedFileContent,\n projectName: project.project.name,\n };\n }\n\n async runSeedTest(seedFile: string, projectName: string): Promise<{ output: string, status: FullResultStatus | 'paused' }> {\n const result = await this.runTestsWithGlobalSetupAndPossiblePause({\n headed: this.computedHeaded,\n locations: ['/' + escapeRegExp(seedFile) + '/'],\n projects: [projectName],\n timeout: 0,\n workers: 1,\n pauseAtEnd: true,\n disableConfigReporters: true,\n failOnLoadErrors: true,\n });\n if (result.status === 'passed')\n result.output += '\\nError: seed test not found.';\n else if (result.status !== 'paused')\n result.output += '\\nError while running the seed test.';\n return result;\n }\n\n async runTestsWithGlobalSetupAndPossiblePause(params: RunTestsParams): Promise<{ output: string, status: FullResultStatus | 'paused' }> {\n const configDir = this._configLocation.configDir;\n const testRunnerAndScreen = await this.createTestRunner();\n const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;\n\n claimStdio();\n try {\n const setupReporter = new ListReporter({ configDir, screen, includeTestId: true });\n const { status } = await testRunner.runGlobalSetup([setupReporter]);\n if (status !== 'passed')\n return { output: testRunnerAndScreen.output.join('\\n'), status };\n } finally {\n releaseStdio();\n }\n\n let status: FullResultStatus | 'paused' = 'passed';\n\n const cleanup = async () => {\n claimStdio();\n try {\n const result = await testRunner.runGlobalTeardown();\n if (status === 'passed')\n status = result.status;\n } finally {\n releaseStdio();\n }\n };\n\n try {\n const reporter = new ListReporter({ configDir, screen, includeTestId: true });\n status = await Promise.race([\n testRunner.runTests(reporter, params).then(result => result.status),\n testRunnerAndScreen.waitForTestPaused().then(() => 'paused' as const),\n ]);\n\n if (status === 'paused') {\n const response = await testRunnerAndScreen.sendMessageToPausedTest!({ request: { initialize: { clientInfo: this._clientInfo } } });\n if (response.error)\n throw new Error(response.error.message);\n testRunnerAndScreen.output.push(response.response.initialize!.pausedMessage);\n return { output: testRunnerAndScreen.output.join('\\n'), status };\n }\n } catch (e) {\n status = 'failed';\n testRunnerAndScreen.output.push(String(e));\n await cleanup();\n return { output: testRunnerAndScreen.output.join('\\n'), status };\n }\n\n await cleanup();\n return { output: testRunnerAndScreen.output.join('\\n'), status };\n }\n\n async close() {\n await this._cleanupTestRunner().catch(logUnhandledError);\n }\n\n async sendMessageToPausedTest(request: BrowserMCPRequest): Promise<BrowserMCPResponse> {\n const sendMessage = this._testRunnerAndScreen?.sendMessageToPausedTest;\n if (!sendMessage)\n throw new Error('Must setup test before interacting with the page');\n const result = await sendMessage({ request });\n if (result.error)\n throw new Error(result.error.message);\n if (typeof request?.callTool?.arguments?.['intent'] === 'string') {\n const response = parseResponse(result.response.callTool!);\n if (response && !response.isError && response.code)\n this.generatorJournal?.logStep(request.callTool.arguments['intent'], response.code);\n }\n return result.response;\n }\n}\n\nexport function createScreen() {\n const output: string[] = [];\n const stdout = new StringWriteStream(output, 'stdout');\n const stderr = new StringWriteStream(output, 'stderr');\n\n const screen = {\n ...terminalScreen,\n isTTY: false,\n colors: noColors,\n stdout: stdout as unknown as NodeJS.WriteStream,\n stderr: stderr as unknown as NodeJS.WriteStream,\n };\n\n /* eslint-disable no-restricted-properties */\n const originalStdoutWrite = process.stdout.write;\n const originalStderrWrite = process.stderr.write;\n\n const claimStdio = () => {\n process.stdout.write = (chunk: string | Buffer) => {\n stdout.write(chunk);\n return true;\n };\n process.stderr.write = (chunk: string | Buffer) => {\n stderr.write(chunk);\n return true;\n };\n };\n\n const releaseStdio = () => {\n process.stdout.write = originalStdoutWrite;\n process.stderr.write = originalStderrWrite;\n };\n /* eslint-enable no-restricted-properties */\n\n return { screen, claimStdio, releaseStdio, output };\n}\n\nconst bestPracticesMarkdown = `\n# Best practices\n- Do not improvise, do not add directives that were not asked for\n- Use clear, descriptive assertions to validate the expected behavior\n- Use reliable locators from this log\n- Use local variables for locators that are used multiple times\n- Use Playwright waiting assertions and best practices from this log\n- NEVER! use page.waitForLoadState()\n- NEVER! use page.waitForNavigation()\n- NEVER! use page.waitForTimeout()\n- NEVER! use page.evaluate()\n`;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,gBAAe;AACf,gBAAe;AACf,kBAAiB;AAEjB,mBAAmE;AAEnE,kBAA+B;AAC/B,kBAAyB;AACzB,qBAAkC;AAClC,kBAAgC;AAChC,wBAA4C;AAC5C,kBAA4C;AAC5C,qBAA8B;AAC9B,0BAAsC;AACtC,sBAA8B;AAC9B,iBAAkC;AAa3B,MAAM,iBAAiB;AAAA,EAM5B,YAAY,UAAkB,MAAc,MAAgB;AAC1D,SAAK,YAAY;AACjB,SAAK,QAAQ;AACb,SAAK,QAAQ;AACb,SAAK,SAAS,CAAC;AAAA,EACjB;AAAA,EAEA,QAAQ,OAA2B,MAAc;AAC/C,QAAI;AACF,WAAK,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;AAAA,EACpC;AAAA,EAEA,UAAU;AACR,UAAM,SAAmB,CAAC;AAC1B,WAAO,KAAK,QAAQ;AACpB,WAAO,KAAK,KAAK,KAAK;AACtB,WAAO,KAAK,oBAAgB,0BAAY,YAAAA,QAAK,SAAS,KAAK,WAAW,KAAK,MAAM,IAAI,CAAC,CAAC,EAAE;AACzF,WAAO,KAAK,OAAO;AACnB,WAAO,KAAK,KAAK,MAAM,OAAO;AAC9B,WAAO,KAAK,KAAK;AACjB,WAAO,KAAK,SAAS;AACrB,WAAO,KAAK,KAAK,OAAO,IAAI,UAAQ,OAAO,KAAK,KAAK;AAAA;AAAA,EAEvD,KAAK,IAAI;AAAA,OACJ,EAAE,KAAK,MAAM,CAAC;AACj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,KAAK;AAClB,aAAO;AAAA,IACT;AACA,YAAQ,OAAO,QAAQ,CAAC,UAA2B;AACjD,aAAO,MAAM,KAAK;AAClB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,eAAe,MAAM;AACzB,YAAQ,OAAO,QAAQ;AACvB,YAAQ,OAAO,QAAQ;AAAA,EACzB;AAGA,SAAO,EAAE,QAAQ,YAAY,cAAc,OAAO;AACpD;AAEA,MAAM,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": ["path", "os", "fs", "ListReporter", "status"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var testTool_exports = {};
|
|
20
|
+
__export(testTool_exports, {
|
|
21
|
+
defineTestTool: () => defineTestTool
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(testTool_exports);
|
|
24
|
+
function defineTestTool(tool) {
|
|
25
|
+
return tool;
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
defineTestTool
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=testTool.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mcp/test/testTool.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { z } from 'zod';\nimport type { TestContext } from './testContext.js';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport type { ToolSchema } from '../sdk/tool.js';\n\nexport type TestTool<Input extends z.Schema = z.Schema> = {\n schema: ToolSchema<Input>;\n handle: (context: TestContext, params: z.output<Input>) => Promise<CallToolResult>;\n};\n\nexport function defineTestTool<Input extends z.Schema>(tool: TestTool<Input>): TestTool<Input> {\n return tool;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BO,SAAS,eAAuC,MAAwC;AAC7F,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 testTools_exports = {};
|
|
30
|
+
__export(testTools_exports, {
|
|
31
|
+
debugTest: () => debugTest,
|
|
32
|
+
listTests: () => listTests,
|
|
33
|
+
runTests: () => runTests
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(testTools_exports);
|
|
36
|
+
var import_mcpBundle = require("playwright-core/lib/mcpBundle");
|
|
37
|
+
var import_listModeReporter = __toESM(require("../../reporters/listModeReporter"));
|
|
38
|
+
var import_testTool = require("./testTool");
|
|
39
|
+
const listTests = (0, import_testTool.defineTestTool)({
|
|
40
|
+
schema: {
|
|
41
|
+
name: "test_list",
|
|
42
|
+
title: "List tests",
|
|
43
|
+
description: "List tests",
|
|
44
|
+
inputSchema: import_mcpBundle.z.object({}),
|
|
45
|
+
type: "readOnly"
|
|
46
|
+
},
|
|
47
|
+
handle: async (context) => {
|
|
48
|
+
const { testRunner, screen, output } = await context.createTestRunner();
|
|
49
|
+
const reporter = new import_listModeReporter.default({ screen, includeTestId: true });
|
|
50
|
+
await testRunner.listTests(reporter, {});
|
|
51
|
+
return { content: output.map((text) => ({ type: "text", text })) };
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const runTests = (0, import_testTool.defineTestTool)({
|
|
55
|
+
schema: {
|
|
56
|
+
name: "test_run",
|
|
57
|
+
title: "Run tests",
|
|
58
|
+
description: "Run tests",
|
|
59
|
+
inputSchema: import_mcpBundle.z.object({
|
|
60
|
+
locations: import_mcpBundle.z.array(import_mcpBundle.z.string()).optional().describe('Folder, file or location to run: "test/e2e" or "test/e2e/file.spec.ts" or "test/e2e/file.spec.ts:20"'),
|
|
61
|
+
projects: import_mcpBundle.z.array(import_mcpBundle.z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with "chromium" is a good start')
|
|
62
|
+
}),
|
|
63
|
+
type: "readOnly"
|
|
64
|
+
},
|
|
65
|
+
handle: async (context, params) => {
|
|
66
|
+
const { output } = await context.runTestsWithGlobalSetupAndPossiblePause({
|
|
67
|
+
locations: params.locations ?? [],
|
|
68
|
+
projects: params.projects,
|
|
69
|
+
disableConfigReporters: true
|
|
70
|
+
});
|
|
71
|
+
return { content: [{ type: "text", text: output }] };
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const debugTest = (0, import_testTool.defineTestTool)({
|
|
75
|
+
schema: {
|
|
76
|
+
name: "test_debug",
|
|
77
|
+
title: "Debug single test",
|
|
78
|
+
description: "Debug single test",
|
|
79
|
+
inputSchema: import_mcpBundle.z.object({
|
|
80
|
+
test: import_mcpBundle.z.object({
|
|
81
|
+
id: import_mcpBundle.z.string().describe("Test ID to debug."),
|
|
82
|
+
title: import_mcpBundle.z.string().describe("Human readable test title for granting permission to debug the test.")
|
|
83
|
+
})
|
|
84
|
+
}),
|
|
85
|
+
type: "readOnly"
|
|
86
|
+
},
|
|
87
|
+
handle: async (context, params) => {
|
|
88
|
+
const { output, status } = await context.runTestsWithGlobalSetupAndPossiblePause({
|
|
89
|
+
headed: context.computedHeaded,
|
|
90
|
+
locations: [],
|
|
91
|
+
// we can make this faster by passing the test's location, so we don't need to scan all tests to find the ID
|
|
92
|
+
testIds: [params.test.id],
|
|
93
|
+
// For automatic recovery
|
|
94
|
+
timeout: 0,
|
|
95
|
+
workers: 1,
|
|
96
|
+
pauseOnError: true,
|
|
97
|
+
disableConfigReporters: true,
|
|
98
|
+
actionTimeout: 5e3
|
|
99
|
+
});
|
|
100
|
+
return { content: [{ type: "text", text: output }], isError: status !== "paused" && status !== "passed" };
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
debugTest,
|
|
106
|
+
listTests,
|
|
107
|
+
runTests
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=testTools.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/mcp/test/testTools.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from 'playwright-core/lib/mcpBundle';\nimport ListModeReporter from '../../reporters/listModeReporter';\nimport { defineTestTool } from './testTool';\n\nexport const listTests = defineTestTool({\n schema: {\n name: 'test_list',\n title: 'List tests',\n description: 'List tests',\n inputSchema: z.object({}),\n type: 'readOnly',\n },\n\n handle: async context => {\n const { testRunner, screen, output } = await context.createTestRunner();\n const reporter = new ListModeReporter({ screen, includeTestId: true });\n await testRunner.listTests(reporter, {});\n return { content: output.map(text => ({ type: 'text', text })) };\n },\n});\n\nexport const runTests = defineTestTool({\n schema: {\n name: 'test_run',\n title: 'Run tests',\n description: 'Run tests',\n inputSchema: z.object({\n locations: z.array(z.string()).optional().describe('Folder, file or location to run: \"test/e2e\" or \"test/e2e/file.spec.ts\" or \"test/e2e/file.spec.ts:20\"'),\n projects: z.array(z.string()).optional().describe('Projects to run, projects from playwright.config.ts, by default runs all projects. Running with \"chromium\" is a good start'),\n }),\n type: 'readOnly',\n },\n\n handle: async (context, params) => {\n const { output } = await context.runTestsWithGlobalSetupAndPossiblePause({\n locations: params.locations ?? [],\n projects: params.projects,\n disableConfigReporters: true,\n });\n return { content: [{ type: 'text', text: output }] };\n },\n});\n\nexport const debugTest = defineTestTool({\n schema: {\n name: 'test_debug',\n title: 'Debug single test',\n description: 'Debug single test',\n inputSchema: z.object({\n test: z.object({\n id: z.string().describe('Test ID to debug.'),\n title: z.string().describe('Human readable test title for granting permission to debug the test.'),\n }),\n }),\n type: 'readOnly',\n },\n\n handle: async (context, params) => {\n const { output, status } = await context.runTestsWithGlobalSetupAndPossiblePause({\n headed: context.computedHeaded,\n locations: [], // we can make this faster by passing the test's location, so we don't need to scan all tests to find the ID\n testIds: [params.test.id],\n // For automatic recovery\n timeout: 0,\n workers: 1,\n pauseOnError: true,\n disableConfigReporters: true,\n actionTimeout: 5000,\n });\n return { content: [{ type: 'text', text: output }], isError: status !== 'paused' && status !== 'passed' };\n },\n});\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA,uBAAk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AA,IACb,aAAa,mBAAE,OAAO;AAAA,MACpB,MAAM,mBAAE,OAAO;AAAA,QACb,IAAI,mBAAE,OAAO,EAAE,SAAS,mBAAmB;AAAA,QAC3C,OAAO,mBAAE,OAAO,EAAE,SAAS,sEAAsE;AAAA,MACnG,CAAC;AAAA,IACH,CAAC;AAAA,IACD,MAAM;AAAA,EACR;AAAA,EAEA,QAAQ,OAAO,SAAS,WAAW;AACjC,UAAM,EAAE,QAAQ,OAAO,IAAI,MAAM,QAAQ,wCAAwC;AAAA,MAC/E,QAAQ,QAAQ;AAAA,MAChB,WAAW,CAAC;AAAA;AAAA,MACZ,SAAS,CAAC,OAAO,KAAK,EAAE;AAAA;AAAA,MAExB,SAAS;AAAA,MACT,SAAS;AAAA,MACT,cAAc;AAAA,MACd,wBAAwB;AAAA,MACxB,eAAe;AAAA,IACjB,CAAC;AACD,WAAO,EAAE,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,OAAO,CAAC,GAAG,SAAS,WAAW,YAAY,WAAW,SAAS;AAAA,EAC1G;AACF,CAAC;",
|
|
6
|
+
"names": ["ListModeReporter"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 pirates_exports = {};
|
|
30
|
+
__export(pirates_exports, {
|
|
31
|
+
addHook: () => addHook
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(pirates_exports);
|
|
34
|
+
var import_module = __toESM(require("module"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
function addHook(transformHook, shouldTransform, extensions) {
|
|
37
|
+
const extensionsToOverwrite = extensions.filter((e) => e !== ".cjs");
|
|
38
|
+
const allSupportedExtensions = new Set(extensions);
|
|
39
|
+
const loaders = import_module.default._extensions;
|
|
40
|
+
const jsLoader = loaders[".js"];
|
|
41
|
+
for (const extension of extensionsToOverwrite) {
|
|
42
|
+
let newLoader2 = function(mod, filename, ...loaderArgs) {
|
|
43
|
+
if (allSupportedExtensions.has(import_path.default.extname(filename)) && shouldTransform(filename)) {
|
|
44
|
+
let newCompile2 = function(code, file, ...ignoredArgs) {
|
|
45
|
+
mod._compile = oldCompile;
|
|
46
|
+
return oldCompile.call(this, transformHook(code, filename), file);
|
|
47
|
+
};
|
|
48
|
+
var newCompile = newCompile2;
|
|
49
|
+
const oldCompile = mod._compile;
|
|
50
|
+
mod._compile = newCompile2;
|
|
51
|
+
}
|
|
52
|
+
originalLoader.call(this, mod, filename, ...loaderArgs);
|
|
53
|
+
};
|
|
54
|
+
var newLoader = newLoader2;
|
|
55
|
+
const originalLoader = loaders[extension] || jsLoader;
|
|
56
|
+
loaders[extension] = newLoader2;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
addHook
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=pirates.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/third_party/pirates.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * MIT License\n *\n * Copyright (c) 2016-2018 Ari Porad\n * Modifications copyright (c) Microsoft Corporation.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport Module from 'module';\nimport path from 'path';\n\nexport function addHook(transformHook: (code: string, filename: string) => string, shouldTransform: (filename: string) => boolean, extensions: string[]) {\n // This is a shortened and slightly changed version of https://github.com/danez/pirates.\n //\n // We cannot use pirates directly due to https://github.com/microsoft/playwright/issues/35812.\n // If we overwrite the '.cjs', the following code does not run because there is a custom loader defined:\n // https://github.com/nodejs/node/blob/b1973550e09d5a2a07c70be5de6e3ae4722ad230/lib/internal/modules/esm/translators.js#L397-L403\n //\n // Here we rely on the default '.js' loader to handle '.cjs' files.\n const extensionsToOverwrite = extensions.filter(e => e !== '.cjs');\n const allSupportedExtensions = new Set(extensions);\n const loaders = (Module as any)._extensions;\n const jsLoader = loaders['.js'];\n for (const extension of extensionsToOverwrite) {\n const originalLoader = loaders[extension] || jsLoader;\n function newLoader(this: any, mod: any, filename: string, ...loaderArgs: any[]) {\n if (allSupportedExtensions.has(path.extname(filename)) && shouldTransform(filename)) {\n const oldCompile = mod._compile;\n function newCompile(this: any, code: string, file: string, ...ignoredArgs: any[]) {\n // Note: we do not pass |args| downstream to make sure \"esm modules\" loaded through here\n // are treated as \"commonjs\", for example for \".mjs\" files.\n // In theory, we should fix this, but it is a breaking change, even for playwright's own tests.\n mod._compile = oldCompile;\n return oldCompile.call(this, transformHook(code, filename), file);\n }\n mod._compile = newCompile;\n }\n originalLoader.call(this, mod, filename, ...loaderArgs);\n }\n loaders[extension] = newLoader;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,oBAAmB;AACnB,kBAAiB;AAEV,SAAS,QAAQ,eAA2D,iBAAgD,YAAsB;AAQvJ,QAAM,wBAAwB,WAAW,OAAO,OAAK,MAAM,MAAM;AACjE,QAAM,yBAAyB,IAAI,IAAI,UAAU;AACjD,QAAM,UAAW,cAAAA,QAAe;AAChC,QAAM,WAAW,QAAQ,KAAK;AAC9B,aAAW,aAAa,uBAAuB;AAE7C,QAASC,aAAT,SAA8B,KAAU,aAAqB,YAAmB;AAC9E,UAAI,uBAAuB,IAAI,YAAAC,QAAK,QAAQ,QAAQ,CAAC,KAAK,gBAAgB,QAAQ,GAAG;AAEnF,YAASC,cAAT,SAA+B,MAAc,SAAiB,aAAoB;AAIhF,cAAI,WAAW;AACf,iBAAO,WAAW,KAAK,MAAM,cAAc,MAAM,QAAQ,GAAG,IAAI;AAAA,QAClE;AANS,yBAAAA;AADT,cAAM,aAAa,IAAI;AAQvB,YAAI,WAAWA;AAAA,MACjB;AACA,qBAAe,KAAK,MAAM,KAAK,UAAU,GAAG,UAAU;AAAA,IACxD;AAbS,oBAAAF;AADT,UAAM,iBAAiB,QAAQ,SAAS,KAAK;AAe7C,YAAQ,SAAS,IAAIA;AAAA,EACvB;AACF;",
|
|
6
|
+
"names": ["Module", "newLoader", "path", "newCompile"]
|
|
7
|
+
}
|