@ohos-ports/playwright 1.52.0-beta.0

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 (110) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +168 -0
  4. package/ThirdPartyNotices.txt +4011 -0
  5. package/cli.js +19 -0
  6. package/index.d.ts +17 -0
  7. package/index.js +17 -0
  8. package/index.mjs +18 -0
  9. package/jsx-runtime.js +42 -0
  10. package/jsx-runtime.mjs +21 -0
  11. package/lib/common/config.js +272 -0
  12. package/lib/common/configLoader.js +373 -0
  13. package/lib/common/esmLoaderHost.js +100 -0
  14. package/lib/common/expectBundle.js +49 -0
  15. package/lib/common/expectBundleImpl.js +389 -0
  16. package/lib/common/fixtures.js +302 -0
  17. package/lib/common/globals.js +58 -0
  18. package/lib/common/ipc.js +60 -0
  19. package/lib/common/poolBuilder.js +85 -0
  20. package/lib/common/process.js +109 -0
  21. package/lib/common/suiteUtils.js +149 -0
  22. package/lib/common/test.js +313 -0
  23. package/lib/common/testLoader.js +100 -0
  24. package/lib/common/testType.js +306 -0
  25. package/lib/errorContext.js +149 -0
  26. package/lib/fsWatcher.js +67 -0
  27. package/lib/index.js +692 -0
  28. package/lib/internalsForTest.js +42 -0
  29. package/lib/isomorphic/events.js +77 -0
  30. package/lib/isomorphic/folders.js +30 -0
  31. package/lib/isomorphic/stringInternPool.js +69 -0
  32. package/lib/isomorphic/teleReceiver.js +484 -0
  33. package/lib/isomorphic/teleSuiteUpdater.js +137 -0
  34. package/lib/isomorphic/testServerConnection.js +211 -0
  35. package/lib/isomorphic/testServerInterface.js +16 -0
  36. package/lib/isomorphic/testTree.js +307 -0
  37. package/lib/isomorphic/types.d.js +16 -0
  38. package/lib/isomorphic/util.js +28 -0
  39. package/lib/loader/loaderMain.js +59 -0
  40. package/lib/matchers/expect.js +322 -0
  41. package/lib/matchers/matcherHint.js +59 -0
  42. package/lib/matchers/matchers.js +362 -0
  43. package/lib/matchers/toBeTruthy.js +71 -0
  44. package/lib/matchers/toEqual.js +94 -0
  45. package/lib/matchers/toHaveURL.js +117 -0
  46. package/lib/matchers/toMatchAriaSnapshot.js +180 -0
  47. package/lib/matchers/toMatchSnapshot.js +365 -0
  48. package/lib/matchers/toMatchText.js +105 -0
  49. package/lib/plugins/gitCommitInfoPlugin.js +198 -0
  50. package/lib/plugins/index.js +28 -0
  51. package/lib/plugins/webServerPlugin.js +207 -0
  52. package/lib/program.js +407 -0
  53. package/lib/reporters/base.js +540 -0
  54. package/lib/reporters/blob.js +135 -0
  55. package/lib/reporters/dot.js +82 -0
  56. package/lib/reporters/empty.js +32 -0
  57. package/lib/reporters/github.js +127 -0
  58. package/lib/reporters/html.js +579 -0
  59. package/lib/reporters/internalReporter.js +129 -0
  60. package/lib/reporters/json.js +254 -0
  61. package/lib/reporters/junit.js +230 -0
  62. package/lib/reporters/line.js +113 -0
  63. package/lib/reporters/list.js +228 -0
  64. package/lib/reporters/merge.js +511 -0
  65. package/lib/reporters/multiplexer.js +104 -0
  66. package/lib/reporters/reporterV2.js +102 -0
  67. package/lib/reporters/teleEmitter.js +269 -0
  68. package/lib/reporters/versions/blobV1.js +16 -0
  69. package/lib/runner/dispatcher.js +484 -0
  70. package/lib/runner/failureTracker.js +62 -0
  71. package/lib/runner/lastRun.js +74 -0
  72. package/lib/runner/loadUtils.js +299 -0
  73. package/lib/runner/loaderHost.js +89 -0
  74. package/lib/runner/processHost.js +165 -0
  75. package/lib/runner/projectUtils.js +235 -0
  76. package/lib/runner/rebase.js +189 -0
  77. package/lib/runner/reporters.js +162 -0
  78. package/lib/runner/runner.js +110 -0
  79. package/lib/runner/sigIntWatcher.js +96 -0
  80. package/lib/runner/taskRunner.js +127 -0
  81. package/lib/runner/tasks.js +400 -0
  82. package/lib/runner/testGroups.js +117 -0
  83. package/lib/runner/testServer.js +477 -0
  84. package/lib/runner/uiModeReporter.js +30 -0
  85. package/lib/runner/vcs.js +72 -0
  86. package/lib/runner/watchMode.js +394 -0
  87. package/lib/runner/workerHost.js +93 -0
  88. package/lib/third_party/tsconfig-loader.js +103 -0
  89. package/lib/transform/babelBundle.js +43 -0
  90. package/lib/transform/babelBundleImpl.js +477 -0
  91. package/lib/transform/compilationCache.js +255 -0
  92. package/lib/transform/esmLoader.js +104 -0
  93. package/lib/transform/esmUtils.js +53 -0
  94. package/lib/transform/portTransport.js +66 -0
  95. package/lib/transform/transform.js +291 -0
  96. package/lib/util.js +407 -0
  97. package/lib/utilsBundle.js +46 -0
  98. package/lib/utilsBundleImpl.js +102 -0
  99. package/lib/worker/fixtureRunner.js +253 -0
  100. package/lib/worker/testInfo.js +422 -0
  101. package/lib/worker/testTracing.js +351 -0
  102. package/lib/worker/timeoutManager.js +174 -0
  103. package/lib/worker/util.js +31 -0
  104. package/lib/worker/workerMain.js +511 -0
  105. package/package.json +64 -0
  106. package/test.d.ts +18 -0
  107. package/test.js +24 -0
  108. package/test.mjs +33 -0
  109. package/types/test.d.ts +10061 -0
  110. package/types/testReporter.d.ts +799 -0
package/lib/program.js ADDED
@@ -0,0 +1,407 @@
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 program_exports = {};
30
+ __export(program_exports, {
31
+ program: () => import_program2.program,
32
+ withRunnerAndMutedWrite: () => withRunnerAndMutedWrite
33
+ });
34
+ module.exports = __toCommonJS(program_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_program = require("@ohos-ports/playwright-core/lib/cli/program");
38
+ var import_utils = require("@ohos-ports/playwright-core/lib/utils");
39
+ var import_config = require("./common/config");
40
+ var import_configLoader = require("./common/configLoader");
41
+ var import_program2 = require("@ohos-ports/playwright-core/lib/cli/program");
42
+ var import_base = require("./reporters/base");
43
+ var import_html = require("./reporters/html");
44
+ var import_merge = require("./reporters/merge");
45
+ var import_projectUtils = require("./runner/projectUtils");
46
+ var import_runner = require("./runner/runner");
47
+ var testServer = __toESM(require("./runner/testServer"));
48
+ var import_watchMode = require("./runner/watchMode");
49
+ var import_util = require("./util");
50
+ function addTestCommand(program3) {
51
+ const command = program3.command("test [test-filter...]");
52
+ command.description("run tests with Playwright Test");
53
+ const options = testOptions.sort((a, b) => a[0].replace(/-/g, "").localeCompare(b[0].replace(/-/g, "")));
54
+ options.forEach(([name, description]) => command.option(name, description));
55
+ command.action(async (args, opts) => {
56
+ try {
57
+ await runTests(args, opts);
58
+ } catch (e) {
59
+ console.error(e);
60
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
61
+ }
62
+ });
63
+ command.addHelpText("afterAll", `
64
+ Arguments [test-filter...]:
65
+ Pass arguments to filter test files. Each argument is treated as a regular expression. Matching is performed against the absolute file paths.
66
+
67
+ Examples:
68
+ $ npx playwright test my.spec.ts
69
+ $ npx playwright test some.spec.ts:42
70
+ $ npx playwright test --headed
71
+ $ npx playwright test --project=webkit`);
72
+ }
73
+ function addListFilesCommand(program3) {
74
+ const command = program3.command("list-files [file-filter...]", { hidden: true });
75
+ command.description("List files with Playwright Test tests");
76
+ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
77
+ command.option("--project <project-name...>", `Only run tests from the specified list of projects, supports '*' wildcard (default: list all projects)`);
78
+ command.action(async (args, opts) => listTestFiles(opts));
79
+ }
80
+ function addClearCacheCommand(program3) {
81
+ const command = program3.command("clear-cache");
82
+ command.description("clears build and test caches");
83
+ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
84
+ command.action(async (opts) => {
85
+ const config = await (0, import_configLoader.loadConfigFromFileRestartIfNeeded)(opts.config);
86
+ if (!config)
87
+ return;
88
+ const runner = new import_runner.Runner(config);
89
+ const { status } = await runner.clearCache();
90
+ const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
91
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
92
+ });
93
+ }
94
+ function addFindRelatedTestFilesCommand(program3) {
95
+ const command = program3.command("find-related-test-files [source-files...]", { hidden: true });
96
+ command.description("Returns the list of related tests to the given files");
97
+ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
98
+ command.action(async (files, options) => {
99
+ const resolvedFiles = files.map((file) => import_path.default.resolve(process.cwd(), file));
100
+ await withRunnerAndMutedWrite(options.config, (runner) => runner.findRelatedTestFiles(resolvedFiles));
101
+ });
102
+ }
103
+ function addDevServerCommand(program3) {
104
+ const command = program3.command("dev-server", { hidden: true });
105
+ command.description("start dev server");
106
+ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
107
+ command.action(async (options) => {
108
+ const config = await (0, import_configLoader.loadConfigFromFileRestartIfNeeded)(options.config);
109
+ if (!config)
110
+ return;
111
+ const runner = new import_runner.Runner(config);
112
+ const { status } = await runner.runDevServer();
113
+ const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
114
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
115
+ });
116
+ }
117
+ function addTestServerCommand(program3) {
118
+ const command = program3.command("test-server", { hidden: true });
119
+ command.description("start test server");
120
+ command.option("-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`);
121
+ command.option("--host <host>", "Host to start the server on", "localhost");
122
+ command.option("--port <port>", "Port to start the server on", "0");
123
+ command.action((opts) => runTestServer(opts));
124
+ }
125
+ function addShowReportCommand(program3) {
126
+ const command = program3.command("show-report [report]");
127
+ command.description("show HTML report");
128
+ command.action((report, options) => (0, import_html.showHTMLReport)(report, options.host, +options.port));
129
+ command.option("--host <host>", "Host to serve report on", "localhost");
130
+ command.option("--port <port>", "Port to serve report on", "9323");
131
+ command.addHelpText("afterAll", `
132
+ Arguments [report]:
133
+ When specified, opens given report, otherwise opens last generated report.
134
+
135
+ Examples:
136
+ $ npx playwright show-report
137
+ $ npx playwright show-report playwright-report`);
138
+ }
139
+ function addMergeReportsCommand(program3) {
140
+ const command = program3.command("merge-reports [dir]");
141
+ command.description("merge multiple blob reports (for sharded tests) into a single report");
142
+ command.action(async (dir, options) => {
143
+ try {
144
+ await mergeReports(dir, options);
145
+ } catch (e) {
146
+ console.error(e);
147
+ (0, import_utils.gracefullyProcessExitDoNotHang)(1);
148
+ }
149
+ });
150
+ command.option("-c, --config <file>", `Configuration file. Can be used to specify additional configuration for the output report.`);
151
+ command.option("--reporter <reporter>", `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")`);
152
+ command.addHelpText("afterAll", `
153
+ Arguments [dir]:
154
+ Directory containing blob reports.
155
+
156
+ Examples:
157
+ $ npx playwright merge-reports playwright-report`);
158
+ }
159
+ async function runTests(args, opts) {
160
+ await (0, import_utils.startProfiling)();
161
+ const cliOverrides = overridesFromOptions(opts);
162
+ const config = await (0, import_configLoader.loadConfigFromFileRestartIfNeeded)(opts.config, cliOverrides, opts.deps === false);
163
+ if (!config)
164
+ return;
165
+ config.cliArgs = args;
166
+ config.cliGrep = opts.grep;
167
+ config.cliOnlyChanged = opts.onlyChanged === true ? "HEAD" : opts.onlyChanged;
168
+ config.cliGrepInvert = opts.grepInvert;
169
+ config.cliListOnly = !!opts.list;
170
+ config.cliProjectFilter = opts.project || void 0;
171
+ config.cliPassWithNoTests = !!opts.passWithNoTests;
172
+ config.cliLastFailed = !!opts.lastFailed;
173
+ (0, import_projectUtils.filterProjects)(config.projects, config.cliProjectFilter);
174
+ if (opts.ui || opts.uiHost || opts.uiPort) {
175
+ if (opts.onlyChanged)
176
+ 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.`);
177
+ const status2 = await testServer.runUIMode(opts.config, cliOverrides, {
178
+ host: opts.uiHost,
179
+ port: opts.uiPort ? +opts.uiPort : void 0,
180
+ args,
181
+ grep: opts.grep,
182
+ grepInvert: opts.grepInvert,
183
+ project: opts.project || void 0,
184
+ reporter: Array.isArray(opts.reporter) ? opts.reporter : opts.reporter ? [opts.reporter] : void 0
185
+ });
186
+ await (0, import_utils.stopProfiling)("runner");
187
+ if (status2 === "restarted")
188
+ return;
189
+ const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
190
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2);
191
+ return;
192
+ }
193
+ if (process.env.PWTEST_WATCH) {
194
+ if (opts.onlyChanged)
195
+ 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.`);
196
+ const status2 = await (0, import_watchMode.runWatchModeLoop)(
197
+ (0, import_configLoader.resolveConfigLocation)(opts.config),
198
+ {
199
+ projects: opts.project,
200
+ files: args,
201
+ grep: opts.grep
202
+ }
203
+ );
204
+ await (0, import_utils.stopProfiling)("runner");
205
+ if (status2 === "restarted")
206
+ return;
207
+ const exitCode2 = status2 === "interrupted" ? 130 : status2 === "passed" ? 0 : 1;
208
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode2);
209
+ return;
210
+ }
211
+ const runner = new import_runner.Runner(config);
212
+ const status = await runner.runAllTests();
213
+ await (0, import_utils.stopProfiling)("runner");
214
+ const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
215
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
216
+ }
217
+ async function runTestServer(opts) {
218
+ const host = opts.host || "localhost";
219
+ const port = opts.port ? +opts.port : 0;
220
+ const status = await testServer.runTestServer(opts.config, {}, { host, port });
221
+ if (status === "restarted")
222
+ return;
223
+ const exitCode = status === "interrupted" ? 130 : status === "passed" ? 0 : 1;
224
+ (0, import_utils.gracefullyProcessExitDoNotHang)(exitCode);
225
+ }
226
+ async function withRunnerAndMutedWrite(configFile, callback) {
227
+ const stdoutWrite = process.stdout.write.bind(process.stdout);
228
+ process.stdout.write = (a, b, c) => process.stderr.write(a, b, c);
229
+ try {
230
+ const config = await (0, import_configLoader.loadConfigFromFileRestartIfNeeded)(configFile);
231
+ if (!config)
232
+ return;
233
+ const runner = new import_runner.Runner(config);
234
+ const result = await callback(runner);
235
+ stdoutWrite(JSON.stringify(result, void 0, 2), () => {
236
+ (0, import_utils.gracefullyProcessExitDoNotHang)(0);
237
+ });
238
+ } catch (e) {
239
+ const error = (0, import_util.serializeError)(e);
240
+ error.location = (0, import_base.prepareErrorStack)(e.stack).location;
241
+ stdoutWrite(JSON.stringify({ error }, void 0, 2), () => {
242
+ (0, import_utils.gracefullyProcessExitDoNotHang)(0);
243
+ });
244
+ }
245
+ }
246
+ async function listTestFiles(opts) {
247
+ await withRunnerAndMutedWrite(opts.config, async (runner) => {
248
+ return await runner.listTestFiles();
249
+ });
250
+ }
251
+ async function mergeReports(reportDir, opts) {
252
+ const configFile = opts.config;
253
+ const config = configFile ? await (0, import_configLoader.loadConfigFromFileRestartIfNeeded)(configFile) : await (0, import_configLoader.loadEmptyConfigForMergeReports)();
254
+ if (!config)
255
+ return;
256
+ const dir = import_path.default.resolve(process.cwd(), reportDir || "");
257
+ const dirStat = await import_fs.default.promises.stat(dir).catch((e) => null);
258
+ if (!dirStat)
259
+ throw new Error("Directory does not exist: " + dir);
260
+ if (!dirStat.isDirectory())
261
+ throw new Error(`"${dir}" is not a directory`);
262
+ let reporterDescriptions = resolveReporterOption(opts.reporter);
263
+ if (!reporterDescriptions && configFile)
264
+ reporterDescriptions = config.config.reporter;
265
+ if (!reporterDescriptions)
266
+ reporterDescriptions = [[import_config.defaultReporter]];
267
+ const rootDirOverride = configFile ? config.config.rootDir : void 0;
268
+ await (0, import_merge.createMergedReport)(config, dir, reporterDescriptions, rootDirOverride);
269
+ (0, import_utils.gracefullyProcessExitDoNotHang)(0);
270
+ }
271
+ function overridesFromOptions(options) {
272
+ let updateSnapshots;
273
+ if (["all", "changed", "missing", "none"].includes(options.updateSnapshots))
274
+ updateSnapshots = options.updateSnapshots;
275
+ else
276
+ updateSnapshots = "updateSnapshots" in options ? "changed" : void 0;
277
+ const overrides = {
278
+ failOnFlakyTests: options.failOnFlakyTests ? true : void 0,
279
+ forbidOnly: options.forbidOnly ? true : void 0,
280
+ fullyParallel: options.fullyParallel ? true : void 0,
281
+ globalTimeout: options.globalTimeout ? parseInt(options.globalTimeout, 10) : void 0,
282
+ maxFailures: options.x ? 1 : options.maxFailures ? parseInt(options.maxFailures, 10) : void 0,
283
+ outputDir: options.output ? import_path.default.resolve(process.cwd(), options.output) : void 0,
284
+ quiet: options.quiet ? options.quiet : void 0,
285
+ repeatEach: options.repeatEach ? parseInt(options.repeatEach, 10) : void 0,
286
+ retries: options.retries ? parseInt(options.retries, 10) : void 0,
287
+ reporter: resolveReporterOption(options.reporter),
288
+ shard: resolveShardOption(options.shard),
289
+ timeout: options.timeout ? parseInt(options.timeout, 10) : void 0,
290
+ tsconfig: options.tsconfig ? import_path.default.resolve(process.cwd(), options.tsconfig) : void 0,
291
+ ignoreSnapshots: options.ignoreSnapshots ? !!options.ignoreSnapshots : void 0,
292
+ updateSnapshots,
293
+ updateSourceMethod: options.updateSourceMethod,
294
+ workers: options.workers
295
+ };
296
+ if (options.browser) {
297
+ const browserOpt = options.browser.toLowerCase();
298
+ if (!["all", "chromium", "firefox", "webkit"].includes(browserOpt))
299
+ throw new Error(`Unsupported browser "${options.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
300
+ const browserNames = browserOpt === "all" ? ["chromium", "firefox", "webkit"] : [browserOpt];
301
+ overrides.projects = browserNames.map((browserName) => {
302
+ return {
303
+ name: browserName,
304
+ use: { browserName }
305
+ };
306
+ });
307
+ }
308
+ if (options.headed || options.debug)
309
+ overrides.use = { headless: false };
310
+ if (!options.ui && options.debug) {
311
+ overrides.debug = true;
312
+ process.env.PWDEBUG = "1";
313
+ }
314
+ if (!options.ui && options.trace) {
315
+ if (!kTraceModes.includes(options.trace))
316
+ throw new Error(`Unsupported trace mode "${options.trace}", must be one of ${kTraceModes.map((mode) => `"${mode}"`).join(", ")}`);
317
+ overrides.use = overrides.use || {};
318
+ overrides.use.trace = options.trace;
319
+ }
320
+ if (overrides.tsconfig && !import_fs.default.existsSync(overrides.tsconfig))
321
+ throw new Error(`--tsconfig "${options.tsconfig}" does not exist`);
322
+ return overrides;
323
+ }
324
+ function resolveReporterOption(reporter) {
325
+ if (!reporter || !reporter.length)
326
+ return void 0;
327
+ return reporter.split(",").map((r) => [resolveReporter(r)]);
328
+ }
329
+ function resolveShardOption(shard) {
330
+ if (!shard)
331
+ return void 0;
332
+ const shardPair = shard.split("/");
333
+ if (shardPair.length !== 2) {
334
+ throw new Error(
335
+ `--shard "${shard}", expected format is "current/all", 1-based, for example "3/5".`
336
+ );
337
+ }
338
+ const current = parseInt(shardPair[0], 10);
339
+ const total = parseInt(shardPair[1], 10);
340
+ if (isNaN(total) || total < 1)
341
+ throw new Error(`--shard "${shard}" total must be a positive number`);
342
+ if (isNaN(current) || current < 1 || current > total) {
343
+ throw new Error(
344
+ `--shard "${shard}" current must be a positive number, not greater than shard total`
345
+ );
346
+ }
347
+ return { current, total };
348
+ }
349
+ function resolveReporter(id) {
350
+ if (import_config.builtInReporters.includes(id))
351
+ return id;
352
+ const localPath = import_path.default.resolve(process.cwd(), id);
353
+ if (import_fs.default.existsSync(localPath))
354
+ return localPath;
355
+ return require.resolve(id, { paths: [process.cwd()] });
356
+ }
357
+ const kTraceModes = ["on", "off", "on-first-retry", "on-all-retries", "retain-on-failure", "retain-on-first-failure"];
358
+ const testOptions = [
359
+ /* deprecated */
360
+ ["--browser <browser>", `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")`],
361
+ ["-c, --config <file>", `Configuration file, or a test directory with optional "playwright.config.{m,c}?{js,ts}"`],
362
+ ["--debug", `Run tests with Playwright Inspector. Shortcut for "PWDEBUG=1" environment variable and "--timeout=0 --max-failures=1 --headed --workers=1" options`],
363
+ ["--fail-on-flaky-tests", `Fail if any test is flagged as flaky (default: false)`],
364
+ ["--forbid-only", `Fail if test.only is called (default: false)`],
365
+ ["--fully-parallel", `Run all tests in parallel (default: false)`],
366
+ ["--global-timeout <timeout>", `Maximum time this test suite can run in milliseconds (default: unlimited)`],
367
+ ["-g, --grep <grep>", `Only run tests matching this regular expression (default: ".*")`],
368
+ ["-gv, --grep-invert <grep>", `Only run tests that do not match this regular expression`],
369
+ ["--headed", `Run tests in headed browsers (default: headless)`],
370
+ ["--ignore-snapshots", `Ignore screenshot and snapshot expectations`],
371
+ ["--last-failed", `Only re-run the failures`],
372
+ ["--list", `Collect all the tests and report them, but do not run`],
373
+ ["--max-failures <N>", `Stop after the first N failures`],
374
+ ["--no-deps", "Do not run project dependencies"],
375
+ ["--output <dir>", `Folder for output artifacts (default: "test-results")`],
376
+ ["--only-changed [ref]", `Only run test files that have been changed between 'HEAD' and 'ref'. Defaults to running all uncommitted changes. Only supports Git.`],
377
+ ["--pass-with-no-tests", `Makes test run succeed even if no tests were found`],
378
+ ["--project <project-name...>", `Only run tests from the specified list of projects, supports '*' wildcard (default: run all projects)`],
379
+ ["--quiet", `Suppress stdio`],
380
+ ["--repeat-each <N>", `Run each test N times (default: 1)`],
381
+ ["--reporter <reporter>", `Reporter to use, comma-separated, can be ${import_config.builtInReporters.map((name) => `"${name}"`).join(", ")} (default: "${import_config.defaultReporter}")`],
382
+ ["--retries <retries>", `Maximum retry count for flaky tests, zero for no retries (default: no retries)`],
383
+ ["--shard <shard>", `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`],
384
+ ["--timeout <timeout>", `Specify test timeout threshold in milliseconds, zero for unlimited (default: ${import_config.defaultTimeout})`],
385
+ ["--trace <mode>", `Force tracing mode, can be ${kTraceModes.map((mode) => `"${mode}"`).join(", ")}`],
386
+ ["--tsconfig <path>", `Path to a single tsconfig applicable to all imported files (default: look up tsconfig for each imported file separately)`],
387
+ ["--ui", `Run tests in interactive UI mode`],
388
+ ["--ui-host <host>", "Host to serve UI on; specifying this option opens UI in a browser tab"],
389
+ ["--ui-port <port>", "Port to serve UI on, 0 for any free port; specifying this option opens UI in a browser tab"],
390
+ ["-u, --update-snapshots [mode]", `Update snapshots with actual results. Possible values are "all", "changed", "missing", and "none". Running tests without the flag defaults to "missing"; running tests with the flag but without a value defaults to "changed".`],
391
+ ["--update-source-method <method>", `Chooses the way source is updated. Possible values are 'overwrite', '3way' and 'patch'. Defaults to 'patch'`],
392
+ ["-j, --workers <workers>", `Number of concurrent workers or percentage of logical CPU cores, use 1 to run in a single worker (default: 50%)`],
393
+ ["-x", `Stop after the first failure`]
394
+ ];
395
+ addTestCommand(import_program.program);
396
+ addShowReportCommand(import_program.program);
397
+ addListFilesCommand(import_program.program);
398
+ addMergeReportsCommand(import_program.program);
399
+ addClearCacheCommand(import_program.program);
400
+ addFindRelatedTestFilesCommand(import_program.program);
401
+ addDevServerCommand(import_program.program);
402
+ addTestServerCommand(import_program.program);
403
+ // Annotate the CommonJS export names for ESM import in node:
404
+ 0 && (module.exports = {
405
+ program,
406
+ withRunnerAndMutedWrite
407
+ });