playwright 1.55.1 → 1.56.1

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.
Files changed (105) hide show
  1. package/README.md +3 -3
  2. package/ThirdPartyNotices.txt +3 -3
  3. package/lib/agents/generateAgents.js +263 -0
  4. package/lib/agents/generator.md +102 -0
  5. package/lib/agents/healer.md +78 -0
  6. package/lib/agents/planner.md +135 -0
  7. package/lib/common/config.js +1 -1
  8. package/lib/common/expectBundle.js +3 -0
  9. package/lib/common/expectBundleImpl.js +51 -51
  10. package/lib/index.js +7 -8
  11. package/lib/isomorphic/testServerConnection.js +0 -7
  12. package/lib/isomorphic/testTree.js +35 -8
  13. package/lib/matchers/expect.js +8 -21
  14. package/lib/matchers/matcherHint.js +42 -18
  15. package/lib/matchers/matchers.js +12 -6
  16. package/lib/matchers/toBeTruthy.js +16 -14
  17. package/lib/matchers/toEqual.js +18 -13
  18. package/lib/matchers/toHaveURL.js +12 -27
  19. package/lib/matchers/toMatchAriaSnapshot.js +26 -30
  20. package/lib/matchers/toMatchSnapshot.js +15 -12
  21. package/lib/matchers/toMatchText.js +29 -35
  22. package/lib/mcp/browser/actions.d.js +16 -0
  23. package/lib/mcp/browser/browserContextFactory.js +296 -0
  24. package/lib/mcp/browser/browserServerBackend.js +76 -0
  25. package/lib/mcp/browser/codegen.js +66 -0
  26. package/lib/mcp/browser/config.js +383 -0
  27. package/lib/mcp/browser/context.js +284 -0
  28. package/lib/mcp/browser/response.js +228 -0
  29. package/lib/mcp/browser/sessionLog.js +160 -0
  30. package/lib/mcp/browser/tab.js +277 -0
  31. package/lib/mcp/browser/tools/common.js +63 -0
  32. package/lib/mcp/browser/tools/console.js +44 -0
  33. package/lib/mcp/browser/tools/dialogs.js +60 -0
  34. package/lib/mcp/browser/tools/evaluate.js +70 -0
  35. package/lib/mcp/browser/tools/files.js +58 -0
  36. package/lib/mcp/browser/tools/form.js +74 -0
  37. package/lib/mcp/browser/tools/install.js +69 -0
  38. package/lib/mcp/browser/tools/keyboard.js +85 -0
  39. package/lib/mcp/browser/tools/mouse.js +107 -0
  40. package/lib/mcp/browser/tools/navigate.js +62 -0
  41. package/lib/mcp/browser/tools/network.js +54 -0
  42. package/lib/mcp/browser/tools/pdf.js +59 -0
  43. package/lib/mcp/browser/tools/screenshot.js +88 -0
  44. package/lib/mcp/browser/tools/snapshot.js +182 -0
  45. package/lib/mcp/browser/tools/tabs.js +67 -0
  46. package/lib/mcp/browser/tools/tool.js +49 -0
  47. package/lib/mcp/browser/tools/tracing.js +74 -0
  48. package/lib/mcp/browser/tools/utils.js +100 -0
  49. package/lib/mcp/browser/tools/verify.js +154 -0
  50. package/lib/mcp/browser/tools/wait.js +63 -0
  51. package/lib/mcp/browser/tools.js +80 -0
  52. package/lib/mcp/browser/watchdog.js +44 -0
  53. package/lib/mcp/config.d.js +16 -0
  54. package/lib/mcp/extension/cdpRelay.js +351 -0
  55. package/lib/mcp/extension/extensionContextFactory.js +75 -0
  56. package/lib/mcp/extension/protocol.js +28 -0
  57. package/lib/mcp/index.js +61 -0
  58. package/lib/mcp/{tool.js → log.js} +12 -18
  59. package/lib/mcp/program.js +96 -0
  60. package/lib/mcp/{bundle.js → sdk/bundle.js} +24 -2
  61. package/lib/mcp/{exports.js → sdk/exports.js} +12 -10
  62. package/lib/mcp/{transport.js → sdk/http.js} +79 -60
  63. package/lib/mcp/sdk/mdb.js +208 -0
  64. package/lib/mcp/{proxyBackend.js → sdk/proxyBackend.js} +18 -13
  65. package/lib/mcp/sdk/server.js +190 -0
  66. package/lib/mcp/sdk/tool.js +51 -0
  67. package/lib/mcp/test/browserBackend.js +98 -0
  68. package/lib/mcp/test/generatorTools.js +122 -0
  69. package/lib/mcp/test/plannerTools.js +46 -0
  70. package/lib/mcp/test/seed.js +72 -0
  71. package/lib/mcp/test/streams.js +39 -0
  72. package/lib/mcp/test/testBackend.js +97 -0
  73. package/lib/mcp/test/testContext.js +176 -0
  74. package/lib/mcp/test/testTool.js +30 -0
  75. package/lib/mcp/test/testTools.js +115 -0
  76. package/lib/mcpBundleImpl.js +14 -67
  77. package/lib/plugins/webServerPlugin.js +2 -0
  78. package/lib/program.js +68 -0
  79. package/lib/reporters/base.js +15 -17
  80. package/lib/reporters/html.js +39 -26
  81. package/lib/reporters/list.js +8 -4
  82. package/lib/reporters/listModeReporter.js +6 -3
  83. package/lib/reporters/merge.js +3 -1
  84. package/lib/reporters/teleEmitter.js +3 -1
  85. package/lib/runner/dispatcher.js +9 -23
  86. package/lib/runner/failureTracker.js +12 -16
  87. package/lib/runner/loadUtils.js +39 -3
  88. package/lib/runner/projectUtils.js +8 -2
  89. package/lib/runner/tasks.js +18 -7
  90. package/lib/runner/testRunner.js +16 -28
  91. package/lib/runner/testServer.js +17 -23
  92. package/lib/runner/watchMode.js +1 -53
  93. package/lib/runner/workerHost.js +8 -10
  94. package/lib/transform/babelBundleImpl.js +10 -10
  95. package/lib/transform/compilationCache.js +22 -5
  96. package/lib/util.js +12 -16
  97. package/lib/utilsBundleImpl.js +1 -1
  98. package/lib/worker/fixtureRunner.js +15 -7
  99. package/lib/worker/testInfo.js +9 -24
  100. package/lib/worker/workerMain.js +12 -8
  101. package/package.json +7 -3
  102. package/types/test.d.ts +17 -8
  103. package/types/testReporter.d.ts +1 -1
  104. package/lib/mcp/server.js +0 -118
  105. /package/lib/mcp/{inProcessTransport.js → sdk/inProcessTransport.js} +0 -0
@@ -0,0 +1,190 @@
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 server_exports = {};
30
+ __export(server_exports, {
31
+ connect: () => connect,
32
+ createServer: () => createServer,
33
+ firstRootPath: () => firstRootPath,
34
+ start: () => start,
35
+ wrapInProcess: () => wrapInProcess
36
+ });
37
+ module.exports = __toCommonJS(server_exports);
38
+ var import_url = require("url");
39
+ var import_utilsBundle = require("playwright-core/lib/utilsBundle");
40
+ var mcpBundle = __toESM(require("./bundle"));
41
+ var import_http = require("./http");
42
+ var import_inProcessTransport = require("./inProcessTransport");
43
+ const serverDebug = (0, import_utilsBundle.debug)("pw:mcp:server");
44
+ async function connect(factory, transport, runHeartbeat) {
45
+ const server = createServer(factory.name, factory.version, factory.create(), runHeartbeat);
46
+ await server.connect(transport);
47
+ }
48
+ async function wrapInProcess(backend) {
49
+ const server = createServer("Internal", "0.0.0", backend, false);
50
+ return new import_inProcessTransport.InProcessTransport(server);
51
+ }
52
+ function createServer(name, version, backend, runHeartbeat) {
53
+ const server = new mcpBundle.Server({ name, version }, {
54
+ capabilities: {
55
+ tools: {}
56
+ }
57
+ });
58
+ server.setRequestHandler(mcpBundle.ListToolsRequestSchema, async () => {
59
+ serverDebug("listTools");
60
+ const tools = await backend.listTools();
61
+ return { tools };
62
+ });
63
+ let initializePromise;
64
+ server.setRequestHandler(mcpBundle.CallToolRequestSchema, async (request, extra) => {
65
+ serverDebug("callTool", request);
66
+ const progressToken = request.params._meta?.progressToken;
67
+ let progressCounter = 0;
68
+ const progress = progressToken ? (params) => {
69
+ extra.sendNotification({
70
+ method: "notifications/progress",
71
+ params: {
72
+ progressToken,
73
+ progress: params.progress ?? ++progressCounter,
74
+ total: params.total,
75
+ message: params.message
76
+ }
77
+ }).catch(serverDebug);
78
+ } : () => {
79
+ };
80
+ try {
81
+ if (!initializePromise)
82
+ initializePromise = initializeServer(server, backend, runHeartbeat);
83
+ await initializePromise;
84
+ return mergeTextParts(await backend.callTool(request.params.name, request.params.arguments || {}, progress));
85
+ } catch (error) {
86
+ return {
87
+ content: [{ type: "text", text: "### Result\n" + String(error) }],
88
+ isError: true
89
+ };
90
+ }
91
+ });
92
+ addServerListener(server, "close", () => backend.serverClosed?.(server));
93
+ return server;
94
+ }
95
+ const initializeServer = async (server, backend, runHeartbeat) => {
96
+ const capabilities = server.getClientCapabilities();
97
+ let clientRoots = [];
98
+ if (capabilities?.roots) {
99
+ const { roots } = await server.listRoots().catch((e) => {
100
+ serverDebug(e);
101
+ return { roots: [] };
102
+ });
103
+ clientRoots = roots;
104
+ }
105
+ const clientInfo = {
106
+ name: server.getClientVersion()?.name ?? "unknown",
107
+ version: server.getClientVersion()?.version ?? "unknown",
108
+ roots: clientRoots,
109
+ timestamp: Date.now()
110
+ };
111
+ await backend.initialize?.(server, clientInfo);
112
+ if (runHeartbeat)
113
+ startHeartbeat(server);
114
+ };
115
+ const startHeartbeat = (server) => {
116
+ const beat = () => {
117
+ Promise.race([
118
+ server.ping(),
119
+ new Promise((_, reject) => setTimeout(() => reject(new Error("ping timeout")), 5e3))
120
+ ]).then(() => {
121
+ setTimeout(beat, 3e3);
122
+ }).catch(() => {
123
+ void server.close();
124
+ });
125
+ };
126
+ beat();
127
+ };
128
+ function addServerListener(server, event, listener) {
129
+ const oldListener = server[`on${event}`];
130
+ server[`on${event}`] = () => {
131
+ oldListener?.();
132
+ listener();
133
+ };
134
+ }
135
+ async function start(serverBackendFactory, options) {
136
+ if (options.port === void 0) {
137
+ await connect(serverBackendFactory, new mcpBundle.StdioServerTransport(), false);
138
+ return;
139
+ }
140
+ const httpServer = await (0, import_http.startHttpServer)(options);
141
+ const url = (0, import_http.httpAddressToString)(httpServer.address());
142
+ await (0, import_http.installHttpTransport)(httpServer, serverBackendFactory, options.allowedHosts);
143
+ const mcpConfig = { mcpServers: {} };
144
+ mcpConfig.mcpServers[serverBackendFactory.nameInConfig] = {
145
+ url: `${url}/mcp`
146
+ };
147
+ const message = [
148
+ `Listening on ${url}`,
149
+ "Put this in your client config:",
150
+ JSON.stringify(mcpConfig, void 0, 2),
151
+ "For legacy SSE transport support, you can use the /sse endpoint instead."
152
+ ].join("\n");
153
+ console.error(message);
154
+ }
155
+ function firstRootPath(clientInfo) {
156
+ if (clientInfo.roots.length === 0)
157
+ return void 0;
158
+ const firstRootUri = clientInfo.roots[0]?.uri;
159
+ const url = firstRootUri ? new URL(firstRootUri) : void 0;
160
+ return url ? (0, import_url.fileURLToPath)(url) : void 0;
161
+ }
162
+ function mergeTextParts(result) {
163
+ const content = [];
164
+ const testParts = [];
165
+ for (const part of result.content) {
166
+ if (part.type === "text") {
167
+ testParts.push(part.text);
168
+ continue;
169
+ }
170
+ if (testParts.length > 0) {
171
+ content.push({ type: "text", text: testParts.join("\n") });
172
+ testParts.length = 0;
173
+ }
174
+ content.push(part);
175
+ }
176
+ if (testParts.length > 0)
177
+ content.push({ type: "text", text: testParts.join("\n") });
178
+ return {
179
+ ...result,
180
+ content
181
+ };
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ connect,
186
+ createServer,
187
+ firstRootPath,
188
+ start,
189
+ wrapInProcess
190
+ });
@@ -0,0 +1,51 @@
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 tool_exports = {};
20
+ __export(tool_exports, {
21
+ defineToolSchema: () => defineToolSchema,
22
+ toMcpTool: () => toMcpTool
23
+ });
24
+ module.exports = __toCommonJS(tool_exports);
25
+ var import_bundle = require("../sdk/bundle");
26
+ const typesWithIntent = ["action", "assertion", "input"];
27
+ function toMcpTool(tool, options) {
28
+ const inputSchema = options?.addIntent && typesWithIntent.includes(tool.type) ? tool.inputSchema.extend({
29
+ intent: import_bundle.z.string().describe("The intent of the call, for example the test step description plan idea")
30
+ }) : tool.inputSchema;
31
+ const readOnly = tool.type === "readOnly" || tool.type === "assertion";
32
+ return {
33
+ name: tool.name,
34
+ description: tool.description,
35
+ inputSchema: (0, import_bundle.zodToJsonSchema)(inputSchema, { strictUnions: true }),
36
+ annotations: {
37
+ title: tool.title,
38
+ readOnlyHint: readOnly,
39
+ destructiveHint: !readOnly,
40
+ openWorldHint: true
41
+ }
42
+ };
43
+ }
44
+ function defineToolSchema(tool) {
45
+ return tool;
46
+ }
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ defineToolSchema,
50
+ toMcpTool
51
+ });
@@ -0,0 +1,98 @@
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 browserBackend_exports = {};
30
+ __export(browserBackend_exports, {
31
+ runBrowserBackendAtEnd: () => runBrowserBackendAtEnd
32
+ });
33
+ module.exports = __toCommonJS(browserBackend_exports);
34
+ var mcp = __toESM(require("../sdk/exports"));
35
+ var import_globals = require("../../common/globals");
36
+ var import_util = require("../../util");
37
+ var import_config = require("../browser/config");
38
+ var import_browserServerBackend = require("../browser/browserServerBackend");
39
+ var import_tab = require("../browser/tab");
40
+ async function runBrowserBackendAtEnd(context, errorMessage) {
41
+ const testInfo = (0, import_globals.currentTestInfo)();
42
+ if (!testInfo)
43
+ return;
44
+ const shouldPause = errorMessage ? testInfo?._pauseOnError() : testInfo?._pauseAtEnd();
45
+ if (!shouldPause)
46
+ return;
47
+ const lines = [];
48
+ if (errorMessage)
49
+ lines.push(`### Paused on error:`, (0, import_util.stripAnsiEscapes)(errorMessage));
50
+ else
51
+ lines.push(`### Paused at end of test. ready for interaction`);
52
+ for (let i = 0; i < context.pages().length; i++) {
53
+ const page = context.pages()[i];
54
+ const stateSuffix = context.pages().length > 1 ? i + 1 + " of " + context.pages().length : "state";
55
+ lines.push(
56
+ "",
57
+ `### Page ${stateSuffix}`,
58
+ `- Page URL: ${page.url()}`,
59
+ `- Page Title: ${await page.title()}`.trim()
60
+ );
61
+ let console = errorMessage ? await import_tab.Tab.collectConsoleMessages(page) : [];
62
+ console = console.filter((msg) => !msg.type || msg.type === "error");
63
+ if (console.length) {
64
+ lines.push("- Console Messages:");
65
+ for (const message of console)
66
+ lines.push(` - ${message.toString()}`);
67
+ }
68
+ lines.push(
69
+ `- Page Snapshot:`,
70
+ "```yaml",
71
+ await page._snapshotForAI(),
72
+ "```"
73
+ );
74
+ }
75
+ lines.push("");
76
+ if (errorMessage)
77
+ lines.push(`### Task`, `Try recovering from the error prior to continuing`);
78
+ const config = {
79
+ ...import_config.defaultConfig,
80
+ capabilities: ["testing"]
81
+ };
82
+ await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, identityFactory(context)), lines.join("\n"));
83
+ }
84
+ function identityFactory(browserContext) {
85
+ return {
86
+ createContext: async (clientInfo, abortSignal, toolName) => {
87
+ return {
88
+ browserContext,
89
+ close: async () => {
90
+ }
91
+ };
92
+ }
93
+ };
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ runBrowserBackendAtEnd
98
+ });
@@ -0,0 +1,122 @@
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 generatorTools_exports = {};
30
+ __export(generatorTools_exports, {
31
+ generatorReadLog: () => generatorReadLog,
32
+ generatorWriteTest: () => generatorWriteTest,
33
+ setupPage: () => setupPage
34
+ });
35
+ module.exports = __toCommonJS(generatorTools_exports);
36
+ var import_fs = __toESM(require("fs"));
37
+ var import_path = __toESM(require("path"));
38
+ var import_bundle = require("../sdk/bundle");
39
+ var import_testTool = require("./testTool");
40
+ var import_testContext = require("./testContext");
41
+ const setupPage = (0, import_testTool.defineTestTool)({
42
+ schema: {
43
+ name: "generator_setup_page",
44
+ title: "Setup generator page",
45
+ description: "Setup the page for test.",
46
+ inputSchema: import_bundle.z.object({
47
+ plan: import_bundle.z.string().describe("The plan for the test. This should be the actual test plan with all the steps."),
48
+ project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
49
+ seedFile: import_bundle.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.')
50
+ }),
51
+ type: "readOnly"
52
+ },
53
+ handle: async (context, params, progress) => {
54
+ const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
55
+ context.generatorJournal = new import_testContext.GeneratorJournal(context.rootPath, params.plan, seed);
56
+ await context.runSeedTest(seed.file, seed.projectName, progress);
57
+ return { content: [] };
58
+ }
59
+ });
60
+ const generatorReadLog = (0, import_testTool.defineTestTool)({
61
+ schema: {
62
+ name: "generator_read_log",
63
+ title: "Retrieve test log",
64
+ description: "Retrieve the performed test log",
65
+ inputSchema: import_bundle.z.object({}),
66
+ type: "readOnly"
67
+ },
68
+ handle: async (context) => {
69
+ if (!context.generatorJournal)
70
+ throw new Error(`Please setup page using "${setupPage.schema.name}" first.`);
71
+ const result = context.generatorJournal.journal();
72
+ return { content: [{
73
+ type: "text",
74
+ text: result
75
+ }] };
76
+ }
77
+ });
78
+ const generatorWriteTest = (0, import_testTool.defineTestTool)({
79
+ schema: {
80
+ name: "generator_write_test",
81
+ title: "Write test",
82
+ description: "Write the generated test to the test file",
83
+ inputSchema: import_bundle.z.object({
84
+ fileName: import_bundle.z.string().describe("The file to write the test to"),
85
+ code: import_bundle.z.string().describe("The generated test code")
86
+ }),
87
+ type: "readOnly"
88
+ },
89
+ handle: async (context, params) => {
90
+ if (!context.generatorJournal)
91
+ throw new Error(`Please setup page using "${setupPage.schema.name}" first.`);
92
+ const testRunner = context.existingTestRunner();
93
+ if (!testRunner)
94
+ throw new Error("No test runner found, please setup page and perform actions first.");
95
+ const config = await testRunner.loadConfig();
96
+ const dirs = [];
97
+ for (const project of config.projects) {
98
+ const testDir = import_path.default.relative(context.rootPath, project.project.testDir).replace(/\\/g, "/");
99
+ const fileName = params.fileName.replace(/\\/g, "/");
100
+ if (fileName.startsWith(testDir)) {
101
+ const resolvedFile = import_path.default.resolve(context.rootPath, fileName);
102
+ await import_fs.default.promises.mkdir(import_path.default.dirname(resolvedFile), { recursive: true });
103
+ await import_fs.default.promises.writeFile(resolvedFile, params.code);
104
+ return {
105
+ content: [{
106
+ type: "text",
107
+ text: `### Result
108
+ Test written to ${params.fileName}`
109
+ }]
110
+ };
111
+ }
112
+ dirs.push(testDir);
113
+ }
114
+ throw new Error(`Test file did not match any of the test dirs: ${dirs.join(", ")}`);
115
+ }
116
+ });
117
+ // Annotate the CommonJS export names for ESM import in node:
118
+ 0 && (module.exports = {
119
+ generatorReadLog,
120
+ generatorWriteTest,
121
+ setupPage
122
+ });
@@ -0,0 +1,46 @@
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 plannerTools_exports = {};
20
+ __export(plannerTools_exports, {
21
+ setupPage: () => setupPage
22
+ });
23
+ module.exports = __toCommonJS(plannerTools_exports);
24
+ var import_bundle = require("../sdk/bundle");
25
+ var import_testTool = require("./testTool");
26
+ const setupPage = (0, import_testTool.defineTestTool)({
27
+ schema: {
28
+ name: "planner_setup_page",
29
+ title: "Setup planner page",
30
+ description: "Setup the page for test planning",
31
+ inputSchema: import_bundle.z.object({
32
+ project: import_bundle.z.string().optional().describe('Project to use for setup. For example: "chromium", if no project is provided uses the first project in the config.'),
33
+ seedFile: import_bundle.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.')
34
+ }),
35
+ type: "readOnly"
36
+ },
37
+ handle: async (context, params, progress) => {
38
+ const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
39
+ await context.runSeedTest(seed.file, seed.projectName, progress);
40
+ return { content: [] };
41
+ }
42
+ });
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ setupPage
46
+ });
@@ -0,0 +1,72 @@
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 seed_exports = {};
30
+ __export(seed_exports, {
31
+ ensureSeedTest: () => ensureSeedTest,
32
+ seedProject: () => seedProject
33
+ });
34
+ module.exports = __toCommonJS(seed_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_utils = require("playwright-core/lib/utils");
38
+ var import_projectUtils = require("../../runner/projectUtils");
39
+ function seedProject(config, projectName) {
40
+ if (!projectName)
41
+ return (0, import_projectUtils.findTopLevelProjects)(config)[0];
42
+ const project = config.projects.find((p) => p.project.name === projectName);
43
+ if (!project)
44
+ throw new Error(`Project ${projectName} not found`);
45
+ return project;
46
+ }
47
+ async function ensureSeedTest(project, logNew) {
48
+ const files = await (0, import_projectUtils.collectFilesForProject)(project);
49
+ const seed = files.find((file) => import_path.default.basename(file).includes("seed"));
50
+ if (seed)
51
+ return seed;
52
+ const testDir = project.project.testDir;
53
+ const seedFile = import_path.default.resolve(testDir, "seed.spec.ts");
54
+ if (logNew) {
55
+ console.log(`Writing file: ${import_path.default.relative(process.cwd(), seedFile)}`);
56
+ }
57
+ await (0, import_utils.mkdirIfNeeded)(seedFile);
58
+ await import_fs.default.promises.writeFile(seedFile, `import { test, expect } from '@playwright/test';
59
+
60
+ test.describe('Test group', () => {
61
+ test('seed', async ({ page }) => {
62
+ // generate code here.
63
+ });
64
+ });
65
+ `);
66
+ return seedFile;
67
+ }
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ ensureSeedTest,
71
+ seedProject
72
+ });
@@ -0,0 +1,39 @@
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 streams_exports = {};
20
+ __export(streams_exports, {
21
+ StringWriteStream: () => StringWriteStream
22
+ });
23
+ module.exports = __toCommonJS(streams_exports);
24
+ var import_stream = require("stream");
25
+ class StringWriteStream extends import_stream.Writable {
26
+ constructor(progress) {
27
+ super();
28
+ this._progress = progress;
29
+ }
30
+ _write(chunk, encoding, callback) {
31
+ const text = chunk.toString();
32
+ this._progress({ message: text.endsWith("\n") ? text.slice(0, -1) : text });
33
+ callback();
34
+ }
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ StringWriteStream
39
+ });