Add SPA session validation and buglist, update migration docs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-03 21:28:08 +00:00
parent 9be3dfc14e
commit cff287e870
24169 changed files with 10223 additions and 7120 deletions

76
node_modules/playwright/lib/mcp/test/browserBackend.js generated vendored Normal file → Executable file
View File

@@ -1,9 +1,7 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
@@ -17,38 +15,54 @@ var __copyProps = (to, from, except, desc) => {
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var browserBackend_exports = {};
__export(browserBackend_exports, {
runBrowserBackendAtEnd: () => runBrowserBackendAtEnd
createCustomMessageHandler: () => createCustomMessageHandler
});
module.exports = __toCommonJS(browserBackend_exports);
var mcp = __toESM(require("../sdk/exports"));
var import_globals = require("../../common/globals");
var import_util = require("../../util");
var import_config = require("../browser/config");
var import_browserServerBackend = require("../browser/browserServerBackend");
var import_tab = require("../browser/tab");
async function runBrowserBackendAtEnd(context, errorMessage) {
const testInfo = (0, import_globals.currentTestInfo)();
if (!testInfo)
return;
const shouldPause = errorMessage ? testInfo?._pauseOnError() : testInfo?._pauseAtEnd();
if (!shouldPause)
return;
var import_util = require("../../util");
function createCustomMessageHandler(testInfo, context) {
let backend;
return async (data) => {
if (data.initialize) {
if (backend)
throw new Error("MCP backend is already initialized");
backend = new import_browserServerBackend.BrowserServerBackend({ ...import_config.defaultConfig, capabilities: ["testing"] }, identityFactory(context));
await backend.initialize(data.initialize.clientInfo);
const pausedMessage = await generatePausedMessage(testInfo, context);
return { initialize: { pausedMessage } };
}
if (data.listTools) {
if (!backend)
throw new Error("MCP backend is not initialized");
return { listTools: await backend.listTools() };
}
if (data.callTool) {
if (!backend)
throw new Error("MCP backend is not initialized");
return { callTool: await backend.callTool(data.callTool.name, data.callTool.arguments) };
}
if (data.close) {
backend?.serverClosed();
backend = void 0;
return { close: {} };
}
throw new Error("Unknown MCP request");
};
}
async function generatePausedMessage(testInfo, context) {
const lines = [];
if (errorMessage)
lines.push(`### Paused on error:`, (0, import_util.stripAnsiEscapes)(errorMessage));
else
if (testInfo.errors.length) {
lines.push(`### Paused on error:`);
for (const error of testInfo.errors)
lines.push((0, import_util.stripAnsiEscapes)(error.message || ""));
} else {
lines.push(`### Paused at end of test. ready for interaction`);
}
for (let i = 0; i < context.pages().length; i++) {
const page = context.pages()[i];
const stateSuffix = context.pages().length > 1 ? i + 1 + " of " + context.pages().length : "state";
@@ -58,7 +72,7 @@ async function runBrowserBackendAtEnd(context, errorMessage) {
`- Page URL: ${page.url()}`,
`- Page Title: ${await page.title()}`.trim()
);
let console = errorMessage ? await import_tab.Tab.collectConsoleMessages(page) : [];
let console = testInfo.errors.length ? await import_tab.Tab.collectConsoleMessages(page) : [];
console = console.filter((msg) => !msg.type || msg.type === "error");
if (console.length) {
lines.push("- Console Messages:");
@@ -68,18 +82,14 @@ async function runBrowserBackendAtEnd(context, errorMessage) {
lines.push(
`- Page Snapshot:`,
"```yaml",
await page._snapshotForAI(),
(await page._snapshotForAI()).full,
"```"
);
}
lines.push("");
if (errorMessage)
if (testInfo.errors.length)
lines.push(`### Task`, `Try recovering from the error prior to continuing`);
const config = {
...import_config.defaultConfig,
capabilities: ["testing"]
};
await mcp.runOnPauseBackendLoop(new import_browserServerBackend.BrowserServerBackend(config, identityFactory(context)), lines.join("\n"));
return lines.join("\n");
}
function identityFactory(browserContext) {
return {
@@ -94,5 +104,5 @@ function identityFactory(browserContext) {
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runBrowserBackendAtEnd
createCustomMessageHandler
});

6
node_modules/playwright/lib/mcp/test/generatorTools.js generated vendored Normal file → Executable file
View File

@@ -50,11 +50,11 @@ const setupPage = (0, import_testTool.defineTestTool)({
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
handle: async (context, params) => {
const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
context.generatorJournal = new import_testContext.GeneratorJournal(context.rootPath, params.plan, seed);
await context.runSeedTest(seed.file, seed.projectName, progress);
return { content: [] };
const { output, status } = await context.runSeedTest(seed.file, seed.projectName);
return { content: [{ type: "text", text: output }], isError: status !== "paused" };
}
});
const generatorReadLog = (0, import_testTool.defineTestTool)({

108
node_modules/playwright/lib/mcp/test/plannerTools.js generated vendored Normal file → Executable file
View File

@@ -1,7 +1,9 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
@@ -15,12 +17,24 @@ var __copyProps = (to, from, except, desc) => {
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plannerTools_exports = {};
__export(plannerTools_exports, {
setupPage: () => setupPage
saveTestPlan: () => saveTestPlan,
setupPage: () => setupPage,
submitTestPlan: () => submitTestPlan
});
module.exports = __toCommonJS(plannerTools_exports);
var import_fs = __toESM(require("fs"));
var import_path = __toESM(require("path"));
var import_bundle = require("../sdk/bundle");
var import_testTool = require("./testTool");
const setupPage = (0, import_testTool.defineTestTool)({
@@ -34,13 +48,97 @@ const setupPage = (0, import_testTool.defineTestTool)({
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
handle: async (context, params) => {
const seed = await context.getOrCreateSeedFile(params.seedFile, params.project);
await context.runSeedTest(seed.file, seed.projectName, progress);
return { content: [] };
const { output, status } = await context.runSeedTest(seed.file, seed.projectName);
return { content: [{ type: "text", text: output }], isError: status !== "paused" };
}
});
const planSchema = import_bundle.z.object({
overview: import_bundle.z.string().describe("A brief overview of the application to be tested"),
suites: import_bundle.z.array(import_bundle.z.object({
name: import_bundle.z.string().describe("The name of the suite"),
seedFile: import_bundle.z.string().describe("A seed file that was used to setup the page for testing."),
tests: import_bundle.z.array(import_bundle.z.object({
name: import_bundle.z.string().describe("The name of the test"),
file: import_bundle.z.string().describe('The file the test should be saved to, for example: "tests/<suite-name>/<test-name>.spec.ts".'),
steps: import_bundle.z.array(import_bundle.z.string().describe(`The steps to be executed to perform the test. For example: 'Click on the "Submit" button'`)),
expectedResults: import_bundle.z.array(import_bundle.z.string().describe("The expected results of the steps for test to verify."))
}))
}))
});
const submitTestPlan = (0, import_testTool.defineTestTool)({
schema: {
name: "planner_submit_plan",
title: "Submit test plan",
description: "Submit the test plan to the test planner",
inputSchema: planSchema,
type: "readOnly"
},
handle: async (context, params) => {
return {
content: [{
type: "text",
text: JSON.stringify(params, null, 2)
}]
};
}
});
const saveTestPlan = (0, import_testTool.defineTestTool)({
schema: {
name: "planner_save_plan",
title: "Save test plan as markdown file",
description: "Save the test plan as a markdown file",
inputSchema: planSchema.extend({
name: import_bundle.z.string().describe('The name of the test plan, for example: "Test Plan".'),
fileName: import_bundle.z.string().describe('The file to save the test plan to, for example: "spec/test.plan.md". Relative to the workspace root.')
}),
type: "readOnly"
},
handle: async (context, params) => {
const lines = [];
lines.push(`# ${params.name}`);
lines.push(``);
lines.push(`## Application Overview`);
lines.push(``);
lines.push(params.overview);
lines.push(``);
lines.push(`## Test Scenarios`);
for (let i = 0; i < params.suites.length; i++) {
lines.push(``);
const suite = params.suites[i];
lines.push(`### ${i + 1}. ${suite.name}`);
lines.push(``);
lines.push(`**Seed:** \`${suite.seedFile}\``);
for (let j = 0; j < suite.tests.length; j++) {
lines.push(``);
const test = suite.tests[j];
lines.push(`#### ${i + 1}.${j + 1}. ${test.name}`);
lines.push(``);
lines.push(`**File:** \`${test.file}\``);
lines.push(``);
lines.push(`**Steps:**`);
for (let k = 0; k < test.steps.length; k++)
lines.push(` ${k + 1}. ${test.steps[k]}`);
lines.push(``);
lines.push(`**Expected Results:**`);
for (const result of test.expectedResults)
lines.push(` - ${result}`);
}
}
lines.push(``);
await import_fs.default.promises.writeFile(import_path.default.resolve(context.rootPath, params.fileName), lines.join("\n"));
return {
content: [{
type: "text",
text: `Test plan saved to ${params.fileName}`
}]
};
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
setupPage
saveTestPlan,
setupPage,
submitTestPlan
});

40
node_modules/playwright/lib/mcp/test/seed.js generated vendored Normal file → Executable file
View File

@@ -28,7 +28,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var seed_exports = {};
__export(seed_exports, {
ensureSeedTest: () => ensureSeedTest,
defaultSeedFile: () => defaultSeedFile,
ensureSeedFile: () => ensureSeedFile,
findSeedFile: () => findSeedFile,
seedFileContent: () => seedFileContent,
seedProject: () => seedProject
});
module.exports = __toCommonJS(seed_exports);
@@ -44,29 +47,36 @@ function seedProject(config, projectName) {
throw new Error(`Project ${projectName} not found`);
return project;
}
async function ensureSeedTest(project, logNew) {
async function findSeedFile(project) {
const files = await (0, import_projectUtils.collectFilesForProject)(project);
const seed = files.find((file) => import_path.default.basename(file).includes("seed"));
if (seed)
return seed;
return files.find((file) => import_path.default.basename(file).includes("seed"));
}
function defaultSeedFile(project) {
const testDir = project.project.testDir;
const seedFile = import_path.default.resolve(testDir, "seed.spec.ts");
if (logNew) {
console.log(`Writing file: ${import_path.default.relative(process.cwd(), seedFile)}`);
}
await (0, import_utils.mkdirIfNeeded)(seedFile);
await import_fs.default.promises.writeFile(seedFile, `import { test, expect } from '@playwright/test';
return import_path.default.resolve(testDir, "seed.spec.ts");
}
async function ensureSeedFile(project) {
const seedFile = await findSeedFile(project);
if (seedFile)
return seedFile;
const seedFilePath = defaultSeedFile(project);
await (0, import_utils.mkdirIfNeeded)(seedFilePath);
await import_fs.default.promises.writeFile(seedFilePath, seedFileContent);
return seedFilePath;
}
const seedFileContent = `import { test, expect } from '@playwright/test';
test.describe('Test group', () => {
test('seed', async ({ page }) => {
// generate code here.
});
});
`);
return seedFile;
}
`;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ensureSeedTest,
defaultSeedFile,
ensureSeedFile,
findSeedFile,
seedFileContent,
seedProject
});

13
node_modules/playwright/lib/mcp/test/streams.js generated vendored Normal file → Executable file
View File

@@ -22,14 +22,19 @@ __export(streams_exports, {
});
module.exports = __toCommonJS(streams_exports);
var import_stream = require("stream");
var import_util = require("../../util");
class StringWriteStream extends import_stream.Writable {
constructor(progress) {
constructor(output, stdio) {
super();
this._progress = progress;
this._output = output;
this._prefix = stdio === "stdout" ? "" : "[err] ";
}
_write(chunk, encoding, callback) {
const text = chunk.toString();
this._progress({ message: text.endsWith("\n") ? text.slice(0, -1) : text });
let text = (0, import_util.stripAnsiEscapes)(chunk.toString());
if (text.endsWith("\n"))
text = text.slice(0, -1);
if (text)
this._output.push(this._prefix + text);
callback();
}
}

60
node_modules/playwright/lib/mcp/test/testBackend.js generated vendored Normal file → Executable file
View File

@@ -37,60 +37,62 @@ var testTools = __toESM(require("./testTools.js"));
var generatorTools = __toESM(require("./generatorTools.js"));
var plannerTools = __toESM(require("./plannerTools.js"));
var import_tools = require("../browser/tools");
var import_configLoader = require("../../common/configLoader");
var import_response = require("../browser/response");
var import_bundle = require("../sdk/bundle");
class TestServerBackend {
constructor(configOption, options) {
this.name = "Playwright";
this.version = "0.0.1";
this._tools = [
plannerTools.saveTestPlan,
plannerTools.setupPage,
plannerTools.submitTestPlan,
generatorTools.setupPage,
generatorTools.generatorReadLog,
generatorTools.generatorWriteTest,
testTools.listTests,
testTools.runTests,
testTools.debugTest
testTools.debugTest,
...import_tools.browserTools.map((tool) => wrapBrowserTool(tool))
];
this._context = new import_testContext.TestContext(options);
this._options = options || {};
this._configOption = configOption;
}
async initialize(server, clientInfo) {
const rootPath = mcp.firstRootPath(clientInfo);
if (this._configOption) {
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(this._configOption));
return;
}
if (rootPath) {
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(rootPath));
return;
}
this._context.initialize(rootPath, (0, import_configLoader.resolveConfigLocation)(void 0));
async initialize(clientInfo) {
this._context = new import_testContext.TestContext(clientInfo, this._configOption, this._options);
}
async listTools() {
return [
...this._tools.map((tool) => mcp.toMcpTool(tool.schema)),
...import_tools.browserTools.map((tool) => mcp.toMcpTool(tool.schema, { addIntent: true }))
];
return this._tools.map((tool) => mcp.toMcpTool(tool.schema));
}
async afterCallTool(name, args, result) {
if (!import_tools.browserTools.find((tool) => tool.schema.name === name))
return;
const response = (0, import_response.parseResponse)(result);
if (response && !response.isError && response.code && typeof args?.["intent"] === "string")
this._context.generatorJournal?.logStep(args["intent"], response.code);
}
async callTool(name, args, progress) {
async callTool(name, args) {
const tool = this._tools.find((tool2) => tool2.schema.name === name);
if (!tool)
throw new Error(`Tool not found: ${name}. Available tools: ${this._tools.map((tool2) => tool2.schema.name).join(", ")}`);
const parsedArguments = tool.schema.inputSchema.parse(args || {});
return await tool.handle(this._context, parsedArguments, progress);
try {
return await tool.handle(this._context, tool.schema.inputSchema.parse(args || {}));
} catch (e) {
return { content: [{ type: "text", text: String(e) }], isError: true };
}
}
serverClosed() {
void this._context.close();
}
}
const typesWithIntent = ["action", "assertion", "input"];
function wrapBrowserTool(tool) {
const inputSchema = typesWithIntent.includes(tool.schema.type) ? tool.schema.inputSchema.extend({
intent: import_bundle.z.string().describe("The intent of the call, for example the test step description plan idea")
}) : tool.schema.inputSchema;
return {
schema: {
...tool.schema,
inputSchema
},
handle: async (context, params) => {
const response = await context.sendMessageToPausedTest({ callTool: { name: tool.schema.name, arguments: params } });
return response.callTool;
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TestServerBackend

183
node_modules/playwright/lib/mcp/test/testContext.js generated vendored Normal file → Executable file
View File

@@ -29,10 +29,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
var testContext_exports = {};
__export(testContext_exports, {
GeneratorJournal: () => GeneratorJournal,
TestContext: () => TestContext
TestContext: () => TestContext,
createScreen: () => createScreen
});
module.exports = __toCommonJS(testContext_exports);
var import_fs = __toESM(require("fs"));
var import_os = __toESM(require("os"));
var import_path = __toESM(require("path"));
var import_utils = require("playwright-core/lib/utils");
var import_base = require("../../reporters/base");
@@ -41,6 +43,10 @@ var import_streams = require("./streams");
var import_util = require("../../util");
var import_testRunner = require("../../runner/testRunner");
var import_seed = require("./seed");
var import_exports = require("../sdk/exports");
var import_configLoader = require("../../common/configLoader");
var import_response = require("../browser/response");
var import_log = require("../log");
class GeneratorJournal {
constructor(rootPath, plan, seed) {
this._rootPath = rootPath;
@@ -70,35 +76,55 @@ ${step.code}
}
}
class TestContext {
constructor(options) {
this.options = options;
}
initialize(rootPath, configLocation) {
this.configLocation = configLocation;
this.rootPath = rootPath || configLocation.configDir;
constructor(clientInfo, configPath, options) {
this._clientInfo = clientInfo;
const rootPath = (0, import_exports.firstRootPath)(clientInfo);
this._configLocation = (0, import_configLoader.resolveConfigLocation)(configPath || rootPath);
this.rootPath = rootPath || this._configLocation.configDir;
if (options?.headless !== void 0)
this.computedHeaded = !options.headless;
else
this.computedHeaded = !process.env.CI && !(import_os.default.platform() === "linux" && !process.env.DISPLAY);
}
existingTestRunner() {
return this._testRunner;
return this._testRunnerAndScreen?.testRunner;
}
async _cleanupTestRunner() {
if (!this._testRunnerAndScreen)
return;
await this._testRunnerAndScreen.testRunner.stopTests();
this._testRunnerAndScreen.claimStdio();
try {
await this._testRunnerAndScreen.testRunner.runGlobalTeardown();
} finally {
this._testRunnerAndScreen.releaseStdio();
this._testRunnerAndScreen = void 0;
}
}
async createTestRunner() {
if (this._testRunner)
await this._testRunner.stopTests();
const testRunner = new import_testRunner.TestRunner(this.configLocation, {});
await this._cleanupTestRunner();
const testRunner = new import_testRunner.TestRunner(this._configLocation, {});
await testRunner.initialize({});
this._testRunner = testRunner;
testRunner.on(import_testRunner.TestRunnerEvent.TestFilesChanged, (testFiles) => {
this._testRunner?.emit(import_testRunner.TestRunnerEvent.TestFilesChanged, testFiles);
const testPaused = new import_utils.ManualPromise();
const testRunnerAndScreen = {
...createScreen(),
testRunner,
waitForTestPaused: () => testPaused
};
this._testRunnerAndScreen = testRunnerAndScreen;
testRunner.on(import_testRunner.TestRunnerEvent.TestPaused, (params) => {
testRunnerAndScreen.sendMessageToPausedTest = params.sendMessage;
testPaused.resolve();
});
this._testRunner = testRunner;
return testRunner;
return testRunnerAndScreen;
}
async getOrCreateSeedFile(seedFile, projectName) {
const configDir = this.configLocation.configDir;
const testRunner = await this.createTestRunner();
const configDir = this._configLocation.configDir;
const { testRunner } = await this.createTestRunner();
const config = await testRunner.loadConfig();
const project = (0, import_seed.seedProject)(config, projectName);
if (!seedFile) {
seedFile = await (0, import_seed.ensureSeedTest)(project, false);
seedFile = await (0, import_seed.ensureSeedFile)(project);
} else {
const candidateFiles = [];
const testDir = project.project.testDir;
@@ -123,13 +149,9 @@ class TestContext {
projectName: project.project.name
};
}
async runSeedTest(seedFile, projectName, progress) {
const { screen } = this.createScreen(progress);
const configDir = this.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen });
const testRunner = await this.createTestRunner();
const result = await testRunner.runTests(reporter, {
headed: !this.options?.headless,
async runSeedTest(seedFile, projectName) {
const result = await this.runTestsWithGlobalSetupAndPossiblePause({
headed: this.computedHeaded,
locations: ["/" + (0, import_utils.escapeRegExp)(seedFile) + "/"],
projects: [projectName],
timeout: 0,
@@ -138,24 +160,104 @@ class TestContext {
disableConfigReporters: true,
failOnLoadErrors: true
});
if (result.status === "passed" && !reporter.suite?.allTests().length)
throw new Error("seed test not found.");
if (result.status !== "passed")
throw new Error("Errors while running the seed test.");
if (result.status === "passed")
result.output += "\nError: seed test not found.";
else if (result.status !== "paused")
result.output += "\nError while running the seed test.";
return result;
}
createScreen(progress) {
const stream = new import_streams.StringWriteStream(progress);
const screen = {
...import_base.terminalScreen,
isTTY: false,
colors: import_utils.noColors,
stdout: stream,
stderr: stream
async runTestsWithGlobalSetupAndPossiblePause(params) {
const configDir = this._configLocation.configDir;
const testRunnerAndScreen = await this.createTestRunner();
const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;
claimStdio();
try {
const setupReporter = new import_list.default({ configDir, screen, includeTestId: true });
const { status: status2 } = await testRunner.runGlobalSetup([setupReporter]);
if (status2 !== "passed")
return { output: testRunnerAndScreen.output.join("\n"), status: status2 };
} finally {
releaseStdio();
}
let status = "passed";
const cleanup = async () => {
claimStdio();
try {
const result = await testRunner.runGlobalTeardown();
if (status === "passed")
status = result.status;
} finally {
releaseStdio();
}
};
return { screen, stream };
try {
const reporter = new import_list.default({ configDir, screen, includeTestId: true });
status = await Promise.race([
testRunner.runTests(reporter, params).then((result) => result.status),
testRunnerAndScreen.waitForTestPaused().then(() => "paused")
]);
if (status === "paused") {
const response = await testRunnerAndScreen.sendMessageToPausedTest({ request: { initialize: { clientInfo: this._clientInfo } } });
if (response.error)
throw new Error(response.error.message);
testRunnerAndScreen.output.push(response.response.initialize.pausedMessage);
return { output: testRunnerAndScreen.output.join("\n"), status };
}
} catch (e) {
status = "failed";
testRunnerAndScreen.output.push(String(e));
await cleanup();
return { output: testRunnerAndScreen.output.join("\n"), status };
}
await cleanup();
return { output: testRunnerAndScreen.output.join("\n"), status };
}
async close() {
await this._cleanupTestRunner().catch(import_log.logUnhandledError);
}
async sendMessageToPausedTest(request) {
const sendMessage = this._testRunnerAndScreen?.sendMessageToPausedTest;
if (!sendMessage)
throw new Error("Must setup test before interacting with the page");
const result = await sendMessage({ request });
if (result.error)
throw new Error(result.error.message);
if (typeof request?.callTool?.arguments?.["intent"] === "string") {
const response = (0, import_response.parseResponse)(result.response.callTool);
if (response && !response.isError && response.code)
this.generatorJournal?.logStep(request.callTool.arguments["intent"], response.code);
}
return result.response;
}
}
function createScreen() {
const output = [];
const stdout = new import_streams.StringWriteStream(output, "stdout");
const stderr = new import_streams.StringWriteStream(output, "stderr");
const screen = {
...import_base.terminalScreen,
isTTY: false,
colors: import_utils.noColors,
stdout,
stderr
};
const originalStdoutWrite = process.stdout.write;
const originalStderrWrite = process.stderr.write;
const claimStdio = () => {
process.stdout.write = (chunk) => {
stdout.write(chunk);
return true;
};
process.stderr.write = (chunk) => {
stderr.write(chunk);
return true;
};
};
const releaseStdio = () => {
process.stdout.write = originalStdoutWrite;
process.stderr.write = originalStderrWrite;
};
return { screen, claimStdio, releaseStdio, output };
}
const bestPracticesMarkdown = `
# Best practices
@@ -172,5 +274,6 @@ const bestPracticesMarkdown = `
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
GeneratorJournal,
TestContext
TestContext,
createScreen
});

0
node_modules/playwright/lib/mcp/test/testTool.js generated vendored Normal file → Executable file
View File

33
node_modules/playwright/lib/mcp/test/testTools.js generated vendored Normal file → Executable file
View File

@@ -34,7 +34,6 @@ __export(testTools_exports, {
});
module.exports = __toCommonJS(testTools_exports);
var import_bundle = require("../sdk/bundle");
var import_list = __toESM(require("../../reporters/list"));
var import_listModeReporter = __toESM(require("../../reporters/listModeReporter"));
var import_testTool = require("./testTool");
const listTests = (0, import_testTool.defineTestTool)({
@@ -45,12 +44,11 @@ const listTests = (0, import_testTool.defineTestTool)({
inputSchema: import_bundle.z.object({}),
type: "readOnly"
},
handle: async (context, _, progress) => {
const { screen } = context.createScreen(progress);
handle: async (context) => {
const { testRunner, screen, output } = await context.createTestRunner();
const reporter = new import_listModeReporter.default({ screen, includeTestId: true });
const testRunner = await context.createTestRunner();
await testRunner.listTests(reporter, {});
return { content: [] };
return { content: output.map((text) => ({ type: "text", text })) };
}
});
const runTests = (0, import_testTool.defineTestTool)({
@@ -64,17 +62,13 @@ const runTests = (0, import_testTool.defineTestTool)({
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
const { screen } = context.createScreen(progress);
const configDir = context.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen, includeTestId: true, prefixStdio: "out" });
const testRunner = await context.createTestRunner();
await testRunner.runTests(reporter, {
handle: async (context, params) => {
const { output } = await context.runTestsWithGlobalSetupAndPossiblePause({
locations: params.locations,
projects: params.projects,
disableConfigReporters: true
});
return { content: [] };
return { content: [{ type: "text", text: output }] };
}
});
const debugTest = (0, import_testTool.defineTestTool)({
@@ -90,21 +84,18 @@ const debugTest = (0, import_testTool.defineTestTool)({
}),
type: "readOnly"
},
handle: async (context, params, progress) => {
const { screen } = context.createScreen(progress);
const configDir = context.configLocation.configDir;
const reporter = new import_list.default({ configDir, screen, includeTestId: true, prefixStdio: "out" });
const testRunner = await context.createTestRunner();
await testRunner.runTests(reporter, {
headed: !context.options?.headless,
handle: async (context, params) => {
const { output, status } = await context.runTestsWithGlobalSetupAndPossiblePause({
headed: context.computedHeaded,
testIds: [params.test.id],
// For automatic recovery
timeout: 0,
workers: 1,
pauseOnError: true,
disableConfigReporters: true
disableConfigReporters: true,
actionTimeout: 5e3
});
return { content: [] };
return { content: [{ type: "text", text: output }], isError: status !== "paused" && status !== "passed" };
}
});
// Annotate the CommonJS export names for ESM import in node: