|
f7eb47b…
|
lmata
|
1 |
"use strict"; |
|
f7eb47b…
|
lmata
|
2 |
var __create = Object.create; |
|
f7eb47b…
|
lmata
|
3 |
var __defProp = Object.defineProperty; |
|
f7eb47b…
|
lmata
|
4 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
f7eb47b…
|
lmata
|
5 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
f7eb47b…
|
lmata
|
6 |
var __getProtoOf = Object.getPrototypeOf; |
|
f7eb47b…
|
lmata
|
7 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
f7eb47b…
|
lmata
|
8 |
var __export = (target, all) => { |
|
f7eb47b…
|
lmata
|
9 |
for (var name in all) |
|
f7eb47b…
|
lmata
|
10 |
__defProp(target, name, { get: all[name], enumerable: true }); |
|
f7eb47b…
|
lmata
|
11 |
}; |
|
f7eb47b…
|
lmata
|
12 |
var __copyProps = (to, from, except, desc) => { |
|
f7eb47b…
|
lmata
|
13 |
if (from && typeof from === "object" || typeof from === "function") { |
|
f7eb47b…
|
lmata
|
14 |
for (let key of __getOwnPropNames(from)) |
|
f7eb47b…
|
lmata
|
15 |
if (!__hasOwnProp.call(to, key) && key !== except) |
|
f7eb47b…
|
lmata
|
16 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
f7eb47b…
|
lmata
|
17 |
} |
|
f7eb47b…
|
lmata
|
18 |
return to; |
|
f7eb47b…
|
lmata
|
19 |
}; |
|
f7eb47b…
|
lmata
|
20 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( |
|
f7eb47b…
|
lmata
|
21 |
// If the importer is in node compatibility mode or this is not an ESM |
|
f7eb47b…
|
lmata
|
22 |
// file that has been converted to a CommonJS file using a Babel- |
|
f7eb47b…
|
lmata
|
23 |
// compatible transform (i.e. "__esModule" has not been set), then set |
|
f7eb47b…
|
lmata
|
24 |
// "default" to the CommonJS "module.exports" for node compatibility. |
|
f7eb47b…
|
lmata
|
25 |
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, |
|
f7eb47b…
|
lmata
|
26 |
mod |
|
f7eb47b…
|
lmata
|
27 |
)); |
|
f7eb47b…
|
lmata
|
28 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
f7eb47b…
|
lmata
|
29 |
var program_exports = {}; |
|
f7eb47b…
|
lmata
|
30 |
__export(program_exports, { |
|
f7eb47b…
|
lmata
|
31 |
program: () => import_program2.program |
|
f7eb47b…
|
lmata
|
32 |
}); |
|
f7eb47b…
|
lmata
|
33 |
module.exports = __toCommonJS(program_exports); |
|
f7eb47b…
|
lmata
|
34 |
var import_fs = __toESM(require("fs")); |
|
f7eb47b…
|
lmata
|
35 |
var import_path = __toESM(require("path")); |
|
f7eb47b…
|
lmata
|
36 |
var import_program = require("playwright-core/lib/cli/program"); |
|
f7eb47b…
|
lmata
|
37 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
38 |
var import_config = require("./common/config"); |
|
f7eb47b…
|
lmata
|
39 |
var import_configLoader = require("./common/configLoader"); |
|
f7eb47b…
|
lmata
|
40 |
var import_program2 = require("playwright-core/lib/cli/program"); |
|
f7eb47b…
|
lmata
|
41 |
var import_base = require("./reporters/base"); |
|
f7eb47b…
|
lmata
|
42 |
var import_html = require("./reporters/html"); |
|
f7eb47b…
|
lmata
|
43 |
var import_merge = require("./reporters/merge"); |
|
f7eb47b…
|
lmata
|
44 |
var import_projectUtils = require("./runner/projectUtils"); |
|
f7eb47b…
|
lmata
|
45 |
var testServer = __toESM(require("./runner/testServer")); |
|
f7eb47b…
|
lmata
|
46 |
var import_watchMode = require("./runner/watchMode"); |
|
f7eb47b…
|
lmata
|
47 |
var import_testRunner = require("./runner/testRunner"); |
|
f7eb47b…
|
lmata
|
48 |
var import_reporters = require("./runner/reporters"); |
|
f7eb47b…
|
lmata
|
49 |
var mcp = __toESM(require("./mcp/sdk/exports")); |
|
f7eb47b…
|
lmata
|
50 |
var import_testBackend = require("./mcp/test/testBackend"); |
|
f7eb47b…
|
lmata
|
51 |
var import_program3 = require("./mcp/program"); |
|
f7eb47b…
|
lmata
|
52 |
var import_watchdog = require("./mcp/browser/watchdog"); |
|
f7eb47b…
|
lmata
|
53 |
var import_generateAgents = require("./agents/generateAgents"); |
|
f7eb47b…
|
lmata
|
54 |
const packageJSON = require("../package.json"); |
|
f7eb47b…
|
lmata
|
55 |
function addTestCommand(program3) { |
|
f7eb47b…
|
lmata
|
56 |
const command = program3.command("test [test-filter...]"); |
|
f7eb47b…
|
lmata
|
57 |
command.description("run tests with Playwright Test"); |
|
f7eb47b…
|
lmata
|
58 |
const options = testOptions.sort((a, b) => a[0].replace(/-/g, "").localeCompare(b[0].replace(/-/g, ""))); |
|
f7eb47b…
|
lmata
|
59 |
options.forEach(([name, { description, choices, preset }]) => { |
|
f7eb47b…
|
lmata
|
60 |
const option = command.createOption(name, description); |
|
f7eb47b…
|
lmata
|
61 |
if (choices) |
|
f7eb47b…
|
lmata
|
62 |
option.choices(choices); |
|
f7eb47b…
|
lmata
|
63 |
if (preset) |
|
f7eb47b…
|
lmata
|
64 |
option.preset(preset); |
|
f7eb47b…
|
lmata
|
65 |
command.addOption(option); |
|
f7eb47b…
|
lmata
|
66 |
return command; |
|
f7eb47b…
|
lmata
|
67 |
}); |
|
f7eb47b…
|
lmata
|
68 |
command.action(async (args, opts) => { |
|
f7eb47b…
|
lmata
|
69 |
try { |
|
f7eb47b…
|
lmata
|
70 |
await runTests(args, opts); |
|
f7eb47b…
|
lmata
|
71 |
} catch (e) { |
|
f7eb47b…
|
lmata
|
72 |
console.error(e); |
|
f7eb47b…
|
lmata
|
73 |
(0, import_utils.gracefullyProcessExitDoNotHang)(1); |
|
f7eb47b…
|
lmata
|
74 |
} |
|
f7eb47b…
|
lmata
|
75 |
}); |
|
f7eb47b…
|
lmata
|
76 |
command.addHelpText("afterAll", ` |
|
f7eb47b…
|
lmata
|
77 |
Arguments [test-filter...]: |
|
f7eb47b…
|
lmata
|
78 |
Pass arguments to filter test files. Each argument is treated as a regular expression. Matching is performed against the absolute file paths. |
|
f7eb47b…
|
lmata
|
79 |
|
|
f7eb47b…
|
lmata
|
80 |
Examples: |
|
f7eb47b…
|
lmata
|
81 |
$ npx playwright test my.spec.ts |
|
f7eb47b…
|
lmata
|
82 |
$ npx playwright test some.spec.ts:42 |
|
f7eb47b…
|
lmata
|
83 |
$ npx playwright test --headed |
|
f7eb47b…
|
lmata
|
84 |
$ npx playwright test --project=webkit`); |
|
f7eb47b…
|
lmata
|
85 |
} |
|
f7eb47b…
|
lmata
|
86 |
function addClearCacheCommand(program3) { |
|
f7eb47b…
|
lmata
|
87 |
const command = program3.command("clear-cache"); |
|
f7eb47b…
|
lmata
|
88 |
command.description("clears build and test caches"); |
|
f7eb47b…
|
lmata
|
89 |
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`); |
|
f7eb47b…
|
lmata
|
90 |
command.action(async (opts) => { |
|
f7eb47b…
|
lmata
|
91 |
const runner = new import_testRunner.TestRunner((0, import_configLoader.resolveConfigLocation)(opts.config), {}); |
|
f7eb47b…
|
lmata
|
92 |
const { status } = await runner.clearCache((0, import_reporters.createErrorCollectingReporter)(import_base.terminalScreen)); |
|
f7eb47b…
|
lmata
|
93 |
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1; |
|
f7eb47b…
|
lmata
|
94 |
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode); |
|
f7eb47b…
|
lmata
|
95 |
}); |
|
f7eb47b…
|
lmata
|
96 |
} |
|
f7eb47b…
|
lmata
|
97 |
function addDevServerCommand(program3) { |
|
f7eb47b…
|
lmata
|
98 |
const command = program3.command("dev-server", { hidden: true }); |
|
f7eb47b…
|
lmata
|
99 |
command.description("start dev server"); |
|
f7eb47b…
|
lmata
|
100 |
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`); |
|
f7eb47b…
|
lmata
|
101 |
command.action(async (options) => { |
|
f7eb47b…
|
lmata
|
102 |
const runner = new import_testRunner.TestRunner((0, import_configLoader.resolveConfigLocation)(options.config), {}); |
|
f7eb47b…
|
lmata
|
103 |
await runner.startDevServer((0, import_reporters.createErrorCollectingReporter)(import_base.terminalScreen), "in-process"); |
|
f7eb47b…
|
lmata
|
104 |
}); |
|
f7eb47b…
|
lmata
|
105 |
} |
|
f7eb47b…
|
lmata
|
106 |
function addTestServerCommand(program3) { |
|
f7eb47b…
|
lmata
|
107 |
const command = program3.command("test-server", { hidden: true }); |
|
f7eb47b…
|
lmata
|
108 |
command.description("start test server"); |
|
f7eb47b…
|
lmata
|
109 |
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`); |
|
f7eb47b…
|
lmata
|
110 |
command.option("--host <host>", "Host to start the server on", "localhost"); |
|
f7eb47b…
|
lmata
|
111 |
command.option("--port <port>", "Port to start the server on", "0"); |
|
f7eb47b…
|
lmata
|
112 |
command.action((opts) => runTestServer(opts)); |
|
f7eb47b…
|
lmata
|
113 |
} |
|
f7eb47b…
|
lmata
|
114 |
function addShowReportCommand(program3) { |
|
f7eb47b…
|
lmata
|
115 |
const command = program3.command("show-report [report]"); |
|
f7eb47b…
|
lmata
|
116 |
command.description("show HTML report"); |
|
f7eb47b…
|
lmata
|
117 |
command.action((report, options) => (0, import_html.showHTMLReport)(report, options.host, +options.port)); |
|
f7eb47b…
|
lmata
|
118 |
command.option("--host <host>", "Host to serve report on", "localhost"); |
|
f7eb47b…
|
lmata
|
119 |
command.option("--port <port>", "Port to serve report on", "9323"); |
|
f7eb47b…
|
lmata
|
120 |
command.addHelpText("afterAll", ` |
|
f7eb47b…
|
lmata
|
121 |
Arguments [report]: |
|
f7eb47b…
|
lmata
|
122 |
When specified, opens given report, otherwise opens last generated report. |
|
f7eb47b…
|
lmata
|
123 |
|
|
f7eb47b…
|
lmata
|
124 |
Examples: |
|
f7eb47b…
|
lmata
|
125 |
$ npx playwright show-report |
|
f7eb47b…
|
lmata
|
126 |
$ npx playwright show-report playwright-report`); |
|
f7eb47b…
|
lmata
|
127 |
} |
|
f7eb47b…
|
lmata
|
128 |
function addMergeReportsCommand(program3) { |
|
f7eb47b…
|
lmata
|
129 |
const command = program3.command("merge-reports [dir]"); |
|
f7eb47b…
|
lmata
|
130 |
command.description("merge multiple blob reports (for sharded tests) into a single report"); |
|
f7eb47b…
|
lmata
|
131 |
command.action(async (dir, options) => { |
|
f7eb47b…
|
lmata
|
132 |
try { |
|
f7eb47b…
|
lmata
|
133 |
await mergeReports(dir, options); |
|
f7eb47b…
|
lmata
|
134 |
} catch (e) { |
|
f7eb47b…
|
lmata
|
135 |
console.error(e); |
|
f7eb47b…
|
lmata
|
136 |
(0, import_utils.gracefullyProcessExitDoNotHang)(1); |
|
f7eb47b…
|
lmata
|
137 |
} |
|
f7eb47b…
|
lmata
|
138 |
}); |
|
f7eb47b…
|
lmata
|
139 |
command.option("-c, --config <file>", `Configuration file. Can be used to specify additional configuration for the output report.`); |
|
f7eb47b…
|
lmata
|
140 |
command.option("--reporter <reporter>", `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")`); |
|
f7eb47b…
|
lmata
|
141 |
command.addHelpText("afterAll", ` |
|
f7eb47b…
|
lmata
|
142 |
Arguments [dir]: |
|
f7eb47b…
|
lmata
|
143 |
Directory containing blob reports. |
|
f7eb47b…
|
lmata
|
144 |
|
|
f7eb47b…
|
lmata
|
145 |
Examples: |
|
f7eb47b…
|
lmata
|
146 |
$ npx playwright merge-reports playwright-report`); |
|
f7eb47b…
|
lmata
|
147 |
} |
|
f7eb47b…
|
lmata
|
148 |
function addBrowserMCPServerCommand(program3) { |
|
f7eb47b…
|
lmata
|
149 |
const command = program3.command("run-mcp-server", { hidden: true }); |
|
f7eb47b…
|
lmata
|
150 |
command.description("Interact with the browser over MCP"); |
|
f7eb47b…
|
lmata
|
151 |
(0, import_program3.decorateCommand)(command, packageJSON.version); |
|
f7eb47b…
|
lmata
|
152 |
} |
|
f7eb47b…
|
lmata
|
153 |
function addTestMCPServerCommand(program3) { |
|
f7eb47b…
|
lmata
|
154 |
const command = program3.command("run-test-mcp-server", { hidden: true }); |
|
f7eb47b…
|
lmata
|
155 |
command.description("Interact with the test runner over MCP"); |
|
f7eb47b…
|
lmata
|
156 |
command.option("--headless", "run browser in headless mode, headed by default"); |
|
f7eb47b…
|
lmata
|
157 |
command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`); |
|
f7eb47b…
|
lmata
|
158 |
command.option("--host <host>", "host to bind server to. Default is localhost. Use 0.0.0.0 to bind to all interfaces."); |
|
f7eb47b…
|
lmata
|
159 |
command.option("--port <port>", "port to listen on for SSE transport."); |
|
f7eb47b…
|
lmata
|
160 |
command.action(async (options) => { |
|
f7eb47b…
|
lmata
|
161 |
(0, import_watchdog.setupExitWatchdog)(); |
|
f7eb47b…
|
lmata
|
162 |
const factory = { |
|
f7eb47b…
|
lmata
|
163 |
name: "Playwright Test Runner", |
|
f7eb47b…
|
lmata
|
164 |
nameInConfig: "playwright-test-runner", |
|
f7eb47b…
|
lmata
|
165 |
version: packageJSON.version, |
|
f7eb47b…
|
lmata
|
166 |
create: () => new import_testBackend.TestServerBackend(options.config, { muteConsole: options.port === void 0, headless: options.headless }) |
|
f7eb47b…
|
lmata
|
167 |
}; |
|
f7eb47b…
|
lmata
|
168 |
await mcp.start(factory, { port: options.port === void 0 ? void 0 : +options.port, host: options.host }); |
|
f7eb47b…
|
lmata
|
169 |
}); |
|
f7eb47b…
|
lmata
|
170 |
} |
|
f7eb47b…
|
lmata
|
171 |
function addInitAgentsCommand(program3) { |
|
f7eb47b…
|
lmata
|
172 |
const command = program3.command("init-agents"); |
|
f7eb47b…
|
lmata
|
173 |
command.description("Initialize repository agents"); |
|
f7eb47b…
|
lmata
|
174 |
const option = command.createOption("--loop <loop>", "Agentic loop provider"); |
|
f7eb47b…
|
lmata
|
175 |
option.choices(["claude", "copilot", "opencode", "vscode", "vscode-legacy"]); |
|
f7eb47b…
|
lmata
|
176 |
command.addOption(option); |
|
f7eb47b…
|
lmata
|
177 |
command.option("-c, --config <file>", `Configuration file to find a project to use for seed test`); |
|
f7eb47b…
|
lmata
|
178 |
command.option("--project <project>", "Project to use for seed test"); |
|
f7eb47b…
|
lmata
|
179 |
command.option("--prompts", "Whether to include prompts in the agent initialization"); |
|
f7eb47b…
|
lmata
|
180 |
command.action(async (opts) => { |
|
f7eb47b…
|
lmata
|
181 |
const config = await (0, import_configLoader.loadConfigFromFile)(opts.config); |
|
f7eb47b…
|
lmata
|
182 |
if (opts.loop === "opencode") { |
|
f7eb47b…
|
lmata
|
183 |
await import_generateAgents.OpencodeGenerator.init(config, opts.project, opts.prompts); |
|
f7eb47b…
|
lmata
|
184 |
} else if (opts.loop === "vscode-legacy") { |
|
f7eb47b…
|
lmata
|
185 |
await import_generateAgents.VSCodeGenerator.init(config, opts.project); |
|
f7eb47b…
|
lmata
|
186 |
} else if (opts.loop === "claude") { |
|
f7eb47b…
|
lmata
|
187 |
await import_generateAgents.ClaudeGenerator.init(config, opts.project, opts.prompts); |
|
f7eb47b…
|
lmata
|
188 |
} else { |
|
f7eb47b…
|
lmata
|
189 |
await import_generateAgents.CopilotGenerator.init(config, opts.project, opts.prompts); |
|
f7eb47b…
|
lmata
|
190 |
return; |
|
f7eb47b…
|
lmata
|
191 |
} |
|
f7eb47b…
|
lmata
|
192 |
}); |
|
f7eb47b…
|
lmata
|
193 |
} |
|
f7eb47b…
|
lmata
|
194 |
async function runTests(args, opts) { |
|
f7eb47b…
|
lmata
|
195 |
await (0, import_utils.startProfiling)(); |
|
f7eb47b…
|
lmata
|
196 |
const cliOverrides = overridesFromOptions(opts); |
|
f7eb47b…
|
lmata
|
197 |
const config = await (0, import_configLoader.loadConfigFromFile)(opts.config, cliOverrides, opts.deps === false); |
|
f7eb47b…
|
lmata
|
198 |
config.cliArgs = args; |
|
f7eb47b…
|
lmata
|
199 |
config.cliGrep = opts.grep; |
|
f7eb47b…
|
lmata
|
200 |
config.cliOnlyChanged = opts.onlyChanged === true ? "HEAD" : opts.onlyChanged; |
|
f7eb47b…
|
lmata
|
201 |
config.cliGrepInvert = opts.grepInvert; |
|
f7eb47b…
|
lmata
|
202 |
config.cliListOnly = !!opts.list; |
|
f7eb47b…
|
lmata
|
203 |
config.cliProjectFilter = opts.project || void 0; |
|
f7eb47b…
|
lmata
|
204 |
config.cliPassWithNoTests = !!opts.passWithNoTests; |
|
f7eb47b…
|
lmata
|
205 |
config.cliLastFailed = !!opts.lastFailed; |
|
f7eb47b…
|
lmata
|
206 |
config.cliTestList = opts.testList ? import_path.default.resolve(process.cwd(), opts.testList) : void 0; |
|
f7eb47b…
|
lmata
|
207 |
config.cliTestListInvert = opts.testListInvert ? import_path.default.resolve(process.cwd(), opts.testListInvert) : void 0; |
|
f7eb47b…
|
lmata
|
208 |
(0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter); |
|
f7eb47b…
|
lmata
|
209 |
if (opts.ui || opts.uiHost || opts.uiPort) { |
|
f7eb47b…
|
lmata
|
210 |
if (opts.onlyChanged) |
|
f7eb47b…
|
lmata
|
211 |
throw new Error(`--only-changed is not supported in UI mode. If you'd like that to change, see https://github.com/microsoft/playwright/issues/15075 for more details.`); |
|
f7eb47b…
|
lmata
|
212 |
const status2 = await testServer.runUIMode(opts.config, cliOverrides, { |
|
f7eb47b…
|
lmata
|
213 |
host: opts.uiHost, |
|
f7eb47b…
|
lmata
|
214 |
port: opts.uiPort ? +opts.uiPort : void 0, |
|
f7eb47b…
|
lmata
|
215 |
args, |
|
f7eb47b…
|
lmata
|
216 |
grep: opts.grep, |
|
f7eb47b…
|
lmata
|
217 |
grepInvert: opts.grepInvert, |
|
f7eb47b…
|
lmata
|
218 |
project: opts.project || void 0, |
|
f7eb47b…
|
lmata
|
219 |
reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : void 0 |
|
f7eb47b…
|
lmata
|
220 |
}); |
|
f7eb47b…
|
lmata
|
221 |
await (0, import_utils.stopProfiling)("runner"); |
|
f7eb47b…
|
lmata
|
222 |
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1; |
|
f7eb47b…
|
lmata
|
223 |
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2); |
|
f7eb47b…
|
lmata
|
224 |
return; |
|
f7eb47b…
|
lmata
|
225 |
} |
|
f7eb47b…
|
lmata
|
226 |
if (process.env.PWTEST_WATCH) { |
|
f7eb47b…
|
lmata
|
227 |
if (opts.onlyChanged) |
|
f7eb47b…
|
lmata
|
228 |
throw new Error(`--only-changed is not supported in watch mode. If you'd like that to change, file an issue and let us know about your usecase for it.`); |
|
f7eb47b…
|
lmata
|
229 |
const status2 = await (0, import_watchMode.runWatchModeLoop)( |
|
f7eb47b…
|
lmata
|
230 |
(0, import_configLoader.resolveConfigLocation)(opts.config), |
|
f7eb47b…
|
lmata
|
231 |
{ |
|
f7eb47b…
|
lmata
|
232 |
projects: opts.project, |
|
f7eb47b…
|
lmata
|
233 |
files: args, |
|
f7eb47b…
|
lmata
|
234 |
grep: opts.grep |
|
f7eb47b…
|
lmata
|
235 |
} |
|
f7eb47b…
|
lmata
|
236 |
); |
|
f7eb47b…
|
lmata
|
237 |
await (0, import_utils.stopProfiling)("runner"); |
|
f7eb47b…
|
lmata
|
238 |
const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1; |
|
f7eb47b…
|
lmata
|
239 |
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2); |
|
f7eb47b…
|
lmata
|
240 |
return; |
|
f7eb47b…
|
lmata
|
241 |
} |
|
f7eb47b…
|
lmata
|
242 |
const status = await (0, import_testRunner.runAllTestsWithConfig)(config); |
|
f7eb47b…
|
lmata
|
243 |
await (0, import_utils.stopProfiling)("runner"); |
|
f7eb47b…
|
lmata
|
244 |
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1; |
|
f7eb47b…
|
lmata
|
245 |
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode); |
|
f7eb47b…
|
lmata
|
246 |
} |
|
f7eb47b…
|
lmata
|
247 |
async function runTestServer(opts) { |
|
f7eb47b…
|
lmata
|
248 |
const host = opts.host; |
|
f7eb47b…
|
lmata
|
249 |
const port = opts.port ? +opts.port : void 0; |
|
f7eb47b…
|
lmata
|
250 |
const status = await testServer.runTestServer(opts.config, {}, { host, port }); |
|
f7eb47b…
|
lmata
|
251 |
const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1; |
|
f7eb47b…
|
lmata
|
252 |
(0, import_utils.gracefullyProcessExitDoNotHang)(exitCode); |
|
f7eb47b…
|
lmata
|
253 |
} |
|
f7eb47b…
|
lmata
|
254 |
async function mergeReports(reportDir, opts) { |
|
f7eb47b…
|
lmata
|
255 |
const configFile = opts.config; |
|
f7eb47b…
|
lmata
|
256 |
const config = configFile ? await (0, import_configLoader.loadConfigFromFile)(configFile) : await (0, import_configLoader.loadEmptyConfigForMergeReports)(); |
|
f7eb47b…
|
lmata
|
257 |
const dir = import_path.default.resolve(process.cwd(), reportDir || ""); |
|
f7eb47b…
|
lmata
|
258 |
const dirStat = await import_fs.default.promises.stat(dir).catch((e) => null); |
|
f7eb47b…
|
lmata
|
259 |
if (!dirStat) |
|
f7eb47b…
|
lmata
|
260 |
throw new Error("Directory does not exist: " + dir); |
|
f7eb47b…
|
lmata
|
261 |
if (!dirStat.isDirectory()) |
|
f7eb47b…
|
lmata
|
262 |
throw new Error(`"${dir}" is not a directory`); |
|
f7eb47b…
|
lmata
|
263 |
let reporterDescriptions = resolveReporterOption(opts.reporter); |
|
f7eb47b…
|
lmata
|
264 |
if (!reporterDescriptions && configFile) |
|
f7eb47b…
|
lmata
|
265 |
reporterDescriptions = config.config.reporter; |
|
f7eb47b…
|
lmata
|
266 |
if (!reporterDescriptions) |
|
f7eb47b…
|
lmata
|
267 |
reporterDescriptions = [[import_config.defaultReporter]]; |
|
f7eb47b…
|
lmata
|
268 |
const rootDirOverride = configFile ? config.config.rootDir : void 0; |
|
f7eb47b…
|
lmata
|
269 |
await (0, import_merge.createMergedReport)(config, dir, reporterDescriptions, rootDirOverride); |
|
f7eb47b…
|
lmata
|
270 |
(0, import_utils.gracefullyProcessExitDoNotHang)(0); |
|
f7eb47b…
|
lmata
|
271 |
} |
|
f7eb47b…
|
lmata
|
272 |
function overridesFromOptions(options) { |
|
f7eb47b…
|
lmata
|
273 |
const overrides = { |
|
f7eb47b…
|
lmata
|
274 |
failOnFlakyTests: options.failOnFlakyTests ? true : void 0, |
|
f7eb47b…
|
lmata
|
275 |
forbidOnly: options.forbidOnly ? true : void 0, |
|
f7eb47b…
|
lmata
|
276 |
fullyParallel: options.fullyParallel ? true : void 0, |
|
f7eb47b…
|
lmata
|
277 |
globalTimeout: options.globalTimeout ? parseInt(options.globalTimeout, 10) : void 0, |
|
f7eb47b…
|
lmata
|
278 |
maxFailures: options.x ? 1 : options.maxFailures ? parseInt(options.maxFailures, 10) : void 0, |
|
f7eb47b…
|
lmata
|
279 |
outputDir: options.output ? import_path.default.resolve(process.cwd(), options.output) : void 0, |
|
f7eb47b…
|
lmata
|
280 |
quiet: options.quiet ? options.quiet : void 0, |
|
f7eb47b…
|
lmata
|
281 |
repeatEach: options.repeatEach ? parseInt(options.repeatEach, 10) : void 0, |
|
f7eb47b…
|
lmata
|
282 |
retries: options.retries ? parseInt(options.retries, 10) : void 0, |
|
f7eb47b…
|
lmata
|
283 |
reporter: resolveReporterOption(options.reporter), |
|
f7eb47b…
|
lmata
|
284 |
shard: resolveShardOption(options.shard), |
|
f7eb47b…
|
lmata
|
285 |
shardWeights: resolveShardWeightsOption(), |
|
f7eb47b…
|
lmata
|
286 |
timeout: options.timeout ? parseInt(options.timeout, 10) : void 0, |
|
f7eb47b…
|
lmata
|
287 |
tsconfig: options.tsconfig ? import_path.default.resolve(process.cwd(), options.tsconfig) : void 0, |
|
f7eb47b…
|
lmata
|
288 |
ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : void 0, |
|
f7eb47b…
|
lmata
|
289 |
updateSnapshots: options.updateSnapshots, |
|
f7eb47b…
|
lmata
|
290 |
updateSourceMethod: options.updateSourceMethod, |
|
f7eb47b…
|
lmata
|
291 |
runAgents: options.runAgents, |
|
f7eb47b…
|
lmata
|
292 |
workers: options.workers, |
|
f7eb47b…
|
lmata
|
293 |
pause: process.env.PWPAUSE ? true : void 0 |
|
f7eb47b…
|
lmata
|
294 |
}; |
|
f7eb47b…
|
lmata
|
295 |
if (options.browser) { |
|
f7eb47b…
|
lmata
|
296 |
const browserOpt = options.browser.toLowerCase(); |
|
f7eb47b…
|
lmata
|
297 |
if (!["all", "chromium", "firefox", "webkit"].includes(browserOpt)) |
|
f7eb47b…
|
lmata
|
298 |
throw new Error(`Unsupported browser "${options.browser}", must be one of "all", "chromium", "firefox" or "webkit"`); |
|
f7eb47b…
|
lmata
|
299 |
const browserNames = browserOpt === "all" ? ["chromium", "firefox", "webkit"] : [browserOpt]; |
|
f7eb47b…
|
lmata
|
300 |
overrides.projects = browserNames.map((browserName) => { |
|
f7eb47b…
|
lmata
|
301 |
return { |
|
f7eb47b…
|
lmata
|
302 |
name: browserName, |
|
f7eb47b…
|
lmata
|
303 |
use: { browserName } |
|
f7eb47b…
|
lmata
|
304 |
}; |
|
f7eb47b…
|
lmata
|
305 |
}); |
|
f7eb47b…
|
lmata
|
306 |
} |
|
f7eb47b…
|
lmata
|
307 |
if (options.headed || options.debug || overrides.pause) |
|
f7eb47b…
|
lmata
|
308 |
overrides.use = { headless: false }; |
|
f7eb47b…
|
lmata
|
309 |
if (!options.ui && options.debug) { |
|
f7eb47b…
|
lmata
|
310 |
overrides.debug = true; |
|
f7eb47b…
|
lmata
|
311 |
process.env.PWDEBUG = "1"; |
|
f7eb47b…
|
lmata
|
312 |
} |
|
f7eb47b…
|
lmata
|
313 |
if (!options.ui && options.trace) { |
|
f7eb47b…
|
lmata
|
314 |
overrides.use = overrides.use || {}; |
|
f7eb47b…
|
lmata
|
315 |
overrides.use.trace = options.trace; |
|
f7eb47b…
|
lmata
|
316 |
} |
|
f7eb47b…
|
lmata
|
317 |
if (overrides.tsconfig && !import_fs.default.existsSync(overrides.tsconfig)) |
|
f7eb47b…
|
lmata
|
318 |
throw new Error(`--tsconfig "${options.tsconfig}" does not exist`); |
|
f7eb47b…
|
lmata
|
319 |
return overrides; |
|
f7eb47b…
|
lmata
|
320 |
} |
|
f7eb47b…
|
lmata
|
321 |
function resolveReporterOption(reporter) { |
|
f7eb47b…
|
lmata
|
322 |
if (!reporter || !reporter.length) |
|
f7eb47b…
|
lmata
|
323 |
return void 0; |
|
f7eb47b…
|
lmata
|
324 |
return reporter.split(",").map((r) => [resolveReporter(r)]); |
|
f7eb47b…
|
lmata
|
325 |
} |
|
f7eb47b…
|
lmata
|
326 |
function resolveShardOption(shard) { |
|
f7eb47b…
|
lmata
|
327 |
if (!shard) |
|
f7eb47b…
|
lmata
|
328 |
return void 0; |
|
f7eb47b…
|
lmata
|
329 |
const shardPair = shard.split("/"); |
|
f7eb47b…
|
lmata
|
330 |
if (shardPair.length !== 2) { |
|
f7eb47b…
|
lmata
|
331 |
throw new Error( |
|
f7eb47b…
|
lmata
|
332 |
`--shard "${shard}", expected format is "current/all", 1-based, for example "3/5".` |
|
f7eb47b…
|
lmata
|
333 |
); |
|
f7eb47b…
|
lmata
|
334 |
} |
|
f7eb47b…
|
lmata
|
335 |
const current = parseInt(shardPair[0], 10); |
|
f7eb47b…
|
lmata
|
336 |
const total = parseInt(shardPair[1], 10); |
|
f7eb47b…
|
lmata
|
337 |
if (isNaN(total) || total < 1) |
|
f7eb47b…
|
lmata
|
338 |
throw new Error(`--shard "${shard}" total must be a positive number`); |
|
f7eb47b…
|
lmata
|
339 |
if (isNaN(current) || current < 1 || current > total) { |
|
f7eb47b…
|
lmata
|
340 |
throw new Error( |
|
f7eb47b…
|
lmata
|
341 |
`--shard "${shard}" current must be a positive number, not greater than shard total` |
|
f7eb47b…
|
lmata
|
342 |
); |
|
f7eb47b…
|
lmata
|
343 |
} |
|
f7eb47b…
|
lmata
|
344 |
return { current, total }; |
|
f7eb47b…
|
lmata
|
345 |
} |
|
f7eb47b…
|
lmata
|
346 |
function resolveShardWeightsOption() { |
|
f7eb47b…
|
lmata
|
347 |
const shardWeights = process.env.PWTEST_SHARD_WEIGHTS; |
|
f7eb47b…
|
lmata
|
348 |
if (!shardWeights) |
|
f7eb47b…
|
lmata
|
349 |
return void 0; |
|
f7eb47b…
|
lmata
|
350 |
return shardWeights.split(":").map((w) => { |
|
f7eb47b…
|
lmata
|
351 |
const weight = parseInt(w, 10); |
|
f7eb47b…
|
lmata
|
352 |
if (isNaN(weight) || weight < 0) |
|
f7eb47b…
|
lmata
|
353 |
throw new Error(`PWTEST_SHARD_WEIGHTS="${shardWeights}" weights must be non-negative numbers`); |
|
f7eb47b…
|
lmata
|
354 |
return weight; |
|
f7eb47b…
|
lmata
|
355 |
}); |
|
f7eb47b…
|
lmata
|
356 |
} |
|
f7eb47b…
|
lmata
|
357 |
function resolveReporter(id) { |
|
f7eb47b…
|
lmata
|
358 |
if (import_config.builtInReporters.includes(id)) |
|
f7eb47b…
|
lmata
|
359 |
return id; |
|
f7eb47b…
|
lmata
|
360 |
const localPath = import_path.default.resolve(process.cwd(), id); |
|
f7eb47b…
|
lmata
|
361 |
if (import_fs.default.existsSync(localPath)) |
|
f7eb47b…
|
lmata
|
362 |
return localPath; |
|
f7eb47b…
|
lmata
|
363 |
return require.resolve(id, { paths: [process.cwd()] }); |
|
f7eb47b…
|
lmata
|
364 |
} |
|
f7eb47b…
|
lmata
|
365 |
const kTraceModes = ["on", "off", "on-first-retry", "on-all-retries", "retain-on-failure", "retain-on-first-failure"]; |
|
f7eb47b…
|
lmata
|
366 |
const testOptions = [ |
|
f7eb47b…
|
lmata
|
367 |
/* deprecated */ |
|
f7eb47b…
|
lmata
|
368 |
["--browser <browser>", { description: `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")` }], |
|
f7eb47b…
|
lmata
|
369 |
["-c, --config <file>", { description: `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"` }], |
|
f7eb47b…
|
lmata
|
370 |
["--debug", { description: `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options` }], |
|
f7eb47b…
|
lmata
|
371 |
["--fail-on-flaky-tests", { description: `Fail if any test is flagged as flaky (default: false)` }], |
|
f7eb47b…
|
lmata
|
372 |
["--forbid-only", { description: `Fail if test.only is called (default: false)` }], |
|
f7eb47b…
|
lmata
|
373 |
["--fully-parallel", { description: `Run all tests in parallel (default: false)` }], |
|
f7eb47b…
|
lmata
|
374 |
["--global-timeout <timeout>", { description: `Maximum time this test suite can run in milliseconds (default: unlimited)` }], |
|
f7eb47b…
|
lmata
|
375 |
["-g, --grep <grep>", { description: `Only run tests matching this regular expression (default: ".*")` }], |
|
f7eb47b…
|
lmata
|
376 |
["--grep-invert <grep>", { description: `Only run tests that do not match this regular expression` }], |
|
f7eb47b…
|
lmata
|
377 |
["--headed", { description: `Run tests in headed browsers (default: headless)` }], |
|
f7eb47b…
|
lmata
|
378 |
["--ignore-snapshots", { description: `Ignore screenshot and snapshot expectations` }], |
|
f7eb47b…
|
lmata
|
379 |
["--last-failed", { description: `Only re-run the failures` }], |
|
f7eb47b…
|
lmata
|
380 |
["--list", { description: `Collect all the tests and report them, but do not run` }], |
|
f7eb47b…
|
lmata
|
381 |
["--max-failures <N>", { description: `Stop after the first N failures` }], |
|
f7eb47b…
|
lmata
|
382 |
["--no-deps", { description: `Do not run project dependencies` }], |
|
f7eb47b…
|
lmata
|
383 |
["--output <dir>", { description: `Folder for output artifacts (default: "test-results")` }], |
|
f7eb47b…
|
lmata
|
384 |
["--only-changed [ref]", { description: `Only run test files that have been changed between 'HEAD' and 'ref'. Defaults to running all uncommitted changes. Only supports Git.` }], |
|
f7eb47b…
|
lmata
|
385 |
["--pass-with-no-tests", { description: `Makes test run succeed even if no tests were found` }], |
|
f7eb47b…
|
lmata
|
386 |
["--project <project-name...>", { description: `Only run tests from the specified list of projects, supports '*' wildcard (default: run all projects)` }], |
|
f7eb47b…
|
lmata
|
387 |
["--quiet", { description: `Suppress stdio` }], |
|
f7eb47b…
|
lmata
|
388 |
["--repeat-each <N>", { description: `Run each test N times (default: 1)` }], |
|
f7eb47b…
|
lmata
|
389 |
["--reporter <reporter>", { description: `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")` }], |
|
f7eb47b…
|
lmata
|
390 |
["--retries <retries>", { description: `Maximum retry count for flaky tests, zero for no retries (default: no retries)` }], |
|
f7eb47b…
|
lmata
|
391 |
["--shard <shard>", { description: `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"` }], |
|
f7eb47b…
|
lmata
|
392 |
["--test-list <file>", { description: `Path to a file containing a list of tests to run. See https://playwright.dev/docs/test-cli for more details.` }], |
|
f7eb47b…
|
lmata
|
393 |
["--test-list-invert <file>", { description: `Path to a file containing a list of tests to skip. See https://playwright.dev/docs/test-cli for more details.` }], |
|
f7eb47b…
|
lmata
|
394 |
["--timeout <timeout>", { description: `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${import_config.defaultTimeout})` }], |
|
f7eb47b…
|
lmata
|
395 |
["--trace <mode>", { description: `Force tracing mode`, choices: kTraceModes }], |
|
f7eb47b…
|
lmata
|
396 |
["--tsconfig <path>", { description: `Path to a single tsconfig applicable to all imported files (default: look up tsconfig for each imported file separately)` }], |
|
f7eb47b…
|
lmata
|
397 |
["--ui", { description: `Run tests in interactive UI mode` }], |
|
f7eb47b…
|
lmata
|
398 |
["--ui-host <host>", { description: `Host to serve UI on; specifying this option opens UI in a browser tab` }], |
|
f7eb47b…
|
lmata
|
399 |
["--ui-port <port>", { description: `Port to serve UI on, 0 for any free port; specifying this option opens UI in a browser tab` }], |
|
f7eb47b…
|
lmata
|
400 |
["-u, --update-snapshots [mode]", { description: `Update snapshots with actual results. Running tests without the flag defaults to "missing"`, choices: ["all", "changed", "missing", "none"], preset: "changed" }], |
|
f7eb47b…
|
lmata
|
401 |
["--update-source-method <method>", { description: `Chooses the way source is updated (default: "patch")`, choices: ["overwrite", "3way", "patch"] }], |
|
f7eb47b…
|
lmata
|
402 |
["-j, --workers <workers>", { description: `Number of concurrent workers or percentage of logical CPU cores, use 1 to run in a single worker (default: 50%)` }], |
|
f7eb47b…
|
lmata
|
403 |
["-x", { description: `Stop after the first failure` }] |
|
f7eb47b…
|
lmata
|
404 |
]; |
|
f7eb47b…
|
lmata
|
405 |
addTestCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
406 |
addShowReportCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
407 |
addMergeReportsCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
408 |
addClearCacheCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
409 |
addBrowserMCPServerCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
410 |
addTestMCPServerCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
411 |
addDevServerCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
412 |
addTestServerCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
413 |
addInitAgentsCommand(import_program.program); |
|
f7eb47b…
|
lmata
|
414 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
415 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
416 |
program |
|
f7eb47b…
|
lmata
|
417 |
}); |