playwright 1.55.0-alpha-2025-08-12 → 1.55.0-alpha-2025-08-14

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.

Potentially problematic release.


This version of playwright might be problematic. Click here for more details.

@@ -28,31 +28,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var testServer_exports = {};
30
30
  __export(testServer_exports, {
31
+ TestRunnerEvent: () => TestRunnerEvent,
31
32
  TestServerDispatcher: () => TestServerDispatcher,
32
- resolveCtDirs: () => resolveCtDirs,
33
33
  runTestServer: () => runTestServer,
34
34
  runUIMode: () => runUIMode
35
35
  });
36
36
  module.exports = __toCommonJS(testServer_exports);
37
- var import_fs = __toESM(require("fs"));
38
- var import_path = __toESM(require("path"));
39
37
  var import_util = __toESM(require("util"));
40
38
  var import_server = require("playwright-core/lib/server");
41
39
  var import_utils = require("playwright-core/lib/utils");
42
40
  var import_utilsBundle = require("playwright-core/lib/utilsBundle");
43
- var import_reporters = require("./reporters");
44
- var import_sigIntWatcher = require("./sigIntWatcher");
45
- var import_tasks = require("./tasks");
46
41
  var import_configLoader = require("../common/configLoader");
47
- var import_fsWatcher = require("../fsWatcher");
48
- var import_teleReceiver = require("../isomorphic/teleReceiver");
49
- var import_gitCommitInfoPlugin = require("../plugins/gitCommitInfoPlugin");
50
- var import_webServerPlugin = require("../plugins/webServerPlugin");
51
- var import_base = require("../reporters/base");
52
- var import_internalReporter = require("../reporters/internalReporter");
53
42
  var import_list = __toESM(require("../reporters/list"));
54
- var import_compilationCache = require("../transform/compilationCache");
55
- var import_util2 = require("../util");
43
+ var import_reporters = require("./reporters");
44
+ var import_sigIntWatcher = require("./sigIntWatcher");
45
+ var import_testRunner = require("./testRunner");
56
46
  const originalDebugLog = import_utilsBundle.debug.log;
57
47
  const originalStdoutWrite = process.stdout.write;
58
48
  const originalStderrWrite = process.stderr.write;
@@ -70,18 +60,15 @@ class TestServer {
70
60
  await this._dispatcher?.runGlobalTeardown();
71
61
  }
72
62
  }
63
+ const TestRunnerEvent = {
64
+ TestFilesChanged: "testFilesChanged",
65
+ RecoverFromStepError: "recoverFromStepError"
66
+ };
73
67
  class TestServerDispatcher {
74
68
  constructor(configLocation, configCLIOverrides) {
75
- this._watchedProjectDirs = /* @__PURE__ */ new Set();
76
- this._ignoredProjectOutputs = /* @__PURE__ */ new Set();
77
- this._watchedTestDependencies = /* @__PURE__ */ new Set();
78
- this._queue = Promise.resolve();
79
69
  this._serializer = require.resolve("./uiModeReporter");
80
- this._watchTestDirs = false;
81
70
  this._closeOnDisconnect = false;
82
- this._populateDependenciesOnList = false;
83
- this._configLocation = configLocation;
84
- this._configCLIOverrides = configCLIOverrides;
71
+ this._testRunner = new import_testRunner.TestRunner(configLocation, configCLIOverrides);
85
72
  this.transport = {
86
73
  onconnect: () => {
87
74
  },
@@ -91,27 +78,29 @@ class TestServerDispatcher {
91
78
  (0, import_utils.gracefullyProcessExitDoNotHang)(0);
92
79
  }
93
80
  };
94
- this._watcher = new import_fsWatcher.Watcher((events) => {
95
- const collector = /* @__PURE__ */ new Set();
96
- events.forEach((f) => (0, import_compilationCache.collectAffectedTestFiles)(f.file, collector));
97
- this._dispatchEvent("testFilesChanged", { testFiles: [...collector] });
98
- });
99
81
  this._dispatchEvent = (method, params) => this.transport.sendEvent?.(method, params);
82
+ this._testRunner.on(TestRunnerEvent.TestFilesChanged, (testFiles) => this._dispatchEvent("testFilesChanged", { testFiles }));
83
+ this._testRunner.on(TestRunnerEvent.RecoverFromStepError, (stepId, message, location) => this._dispatchEvent("recoverFromStepError", { stepId, message, location }));
100
84
  }
101
85
  async _wireReporter(messageSink) {
102
86
  return await (0, import_reporters.createReporterForTestServer)(this._serializer, messageSink);
103
87
  }
104
- async _collectingInternalReporter(...extraReporters) {
88
+ async _collectingReporter() {
105
89
  const report = [];
106
- const collectingReporter = await (0, import_reporters.createReporterForTestServer)(this._serializer, (e) => report.push(e));
107
- return { reporter: new import_internalReporter.InternalReporter([collectingReporter, ...extraReporters]), report };
90
+ return {
91
+ reporter: await (0, import_reporters.createReporterForTestServer)(this._serializer, (e) => report.push(e)),
92
+ report
93
+ };
108
94
  }
109
95
  async initialize(params) {
110
96
  this._serializer = params.serializer || require.resolve("./uiModeReporter");
111
97
  this._closeOnDisconnect = !!params.closeOnDisconnect;
112
98
  await this._setInterceptStdio(!!params.interceptStdio);
113
- this._watchTestDirs = !!params.watchTestDirs;
114
- this._populateDependenciesOnList = !!params.populateDependenciesOnList;
99
+ await this._testRunner.initialize({
100
+ watchTestDirs: !!params.watchTestDirs,
101
+ populateDependenciesOnList: !!params.populateDependenciesOnList,
102
+ recoverFromStepErrors: !!params.recoverFromStepErrors
103
+ });
115
104
  }
116
105
  async ping() {
117
106
  }
@@ -121,221 +110,68 @@ class TestServerDispatcher {
121
110
  (0, import_utilsBundle.open)("vscode://file/" + params.location.file + ":" + params.location.line).catch((e) => console.error(e));
122
111
  }
123
112
  async resizeTerminal(params) {
124
- process.stdout.columns = params.cols;
125
- process.stdout.rows = params.rows;
126
- process.stderr.columns = params.cols;
127
- process.stderr.rows = params.rows;
113
+ this._testRunner.resizeTerminal(params);
128
114
  }
129
115
  async checkBrowsers() {
130
- return { hasBrowsers: hasSomeBrowsers() };
116
+ return { hasBrowsers: this._testRunner.hasSomeBrowsers() };
131
117
  }
132
118
  async installBrowsers() {
133
- await installBrowsers();
119
+ await this._testRunner.installBrowsers();
134
120
  }
135
121
  async runGlobalSetup(params) {
136
122
  await this.runGlobalTeardown();
137
- const { reporter, report } = await this._collectingInternalReporter(new import_list.default());
138
- const config = await this._loadConfigOrReportError(reporter, this._configCLIOverrides);
139
- if (!config)
140
- return { status: "failed", report };
141
- const { status, cleanup } = await (0, import_tasks.runTasksDeferCleanup)(new import_tasks.TestRun(config, reporter), [
142
- ...(0, import_tasks.createGlobalSetupTasks)(config)
143
- ]);
144
- if (status !== "passed")
145
- await cleanup();
146
- else
147
- this._globalSetup = { cleanup, report };
123
+ const { reporter, report } = await this._collectingReporter();
124
+ this._globalSetupReport = report;
125
+ const { status } = await this._testRunner.runGlobalSetup([reporter, new import_list.default()]);
148
126
  return { report, status };
149
127
  }
150
128
  async runGlobalTeardown() {
151
- const globalSetup = this._globalSetup;
152
- const status = await globalSetup?.cleanup();
153
- this._globalSetup = void 0;
154
- return { status, report: globalSetup?.report || [] };
129
+ const { status } = await this._testRunner.runGlobalTeardown();
130
+ const report = this._globalSetupReport || [];
131
+ this._globalSetupReport = void 0;
132
+ return { status, report };
155
133
  }
156
134
  async startDevServer(params) {
157
135
  await this.stopDevServer({});
158
- const { reporter, report } = await this._collectingInternalReporter();
159
- const config = await this._loadConfigOrReportError(reporter);
160
- if (!config)
161
- return { report, status: "failed" };
162
- const { status, cleanup } = await (0, import_tasks.runTasksDeferCleanup)(new import_tasks.TestRun(config, reporter), [
163
- (0, import_tasks.createLoadTask)("out-of-process", { failOnLoadErrors: true, filterOnly: false }),
164
- (0, import_tasks.createStartDevServerTask)()
165
- ]);
166
- if (status !== "passed")
167
- await cleanup();
168
- else
169
- this._devServer = { cleanup, report };
136
+ const { reporter, report } = await this._collectingReporter();
137
+ const { status } = await this._testRunner.startDevServer([reporter]);
170
138
  return { report, status };
171
139
  }
172
140
  async stopDevServer(params) {
173
- const devServer = this._devServer;
174
- const status = await devServer?.cleanup();
175
- this._devServer = void 0;
176
- return { status, report: devServer?.report || [] };
141
+ const { status } = await this._testRunner.stopDevServer();
142
+ const report = this._devServerReport || [];
143
+ this._devServerReport = void 0;
144
+ return { status, report };
177
145
  }
178
146
  async clearCache(params) {
179
- const reporter = new import_internalReporter.InternalReporter([]);
180
- const config = await this._loadConfigOrReportError(reporter);
181
- if (!config)
182
- return;
183
- await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
184
- (0, import_tasks.createClearCacheTask)(config)
185
- ]);
147
+ await this._testRunner.clearCache();
186
148
  }
187
149
  async listFiles(params) {
188
- const { reporter, report } = await this._collectingInternalReporter();
189
- const config = await this._loadConfigOrReportError(reporter);
190
- if (!config)
191
- return { status: "failed", report };
192
- config.cliProjectFilter = params.projects?.length ? params.projects : void 0;
193
- const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
194
- (0, import_tasks.createListFilesTask)(),
195
- (0, import_tasks.createReportBeginTask)()
196
- ]);
150
+ const { reporter, report } = await this._collectingReporter();
151
+ const { status } = await this._testRunner.listFiles([reporter], params);
197
152
  return { report, status };
198
153
  }
199
154
  async listTests(params) {
200
- let result;
201
- this._queue = this._queue.then(async () => {
202
- const { config, report, status } = await this._innerListTests(params);
203
- if (config)
204
- await this._updateWatchedDirs(config);
205
- result = { report, status };
206
- }).catch(printInternalError);
207
- await this._queue;
208
- return result;
209
- }
210
- async _innerListTests(params) {
211
- const overrides = {
212
- ...this._configCLIOverrides,
213
- repeatEach: 1,
214
- retries: 0
215
- };
216
- const { reporter, report } = await this._collectingInternalReporter();
217
- const config = await this._loadConfigOrReportError(reporter, overrides);
218
- if (!config)
219
- return { report, reporter, status: "failed" };
220
- config.cliArgs = params.locations || [];
221
- config.cliGrep = params.grep;
222
- config.cliGrepInvert = params.grepInvert;
223
- config.cliProjectFilter = params.projects?.length ? params.projects : void 0;
224
- config.cliListOnly = true;
225
- const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
226
- (0, import_tasks.createLoadTask)("out-of-process", { failOnLoadErrors: false, filterOnly: false, populateDependencies: this._populateDependenciesOnList }),
227
- (0, import_tasks.createReportBeginTask)()
228
- ]);
229
- return { config, report, reporter, status };
230
- }
231
- async _updateWatchedDirs(config) {
232
- this._watchedProjectDirs = /* @__PURE__ */ new Set();
233
- this._ignoredProjectOutputs = /* @__PURE__ */ new Set();
234
- for (const p of config.projects) {
235
- this._watchedProjectDirs.add(p.project.testDir);
236
- this._ignoredProjectOutputs.add(p.project.outputDir);
237
- }
238
- const result = await resolveCtDirs(config);
239
- if (result) {
240
- this._watchedProjectDirs.add(result.templateDir);
241
- this._ignoredProjectOutputs.add(result.outDir);
242
- }
243
- if (this._watchTestDirs)
244
- await this._updateWatcher(false);
245
- }
246
- async _updateWatcher(reportPending) {
247
- await this._watcher.update([...this._watchedProjectDirs, ...this._watchedTestDependencies], [...this._ignoredProjectOutputs], reportPending);
155
+ const { reporter, report } = await this._collectingReporter();
156
+ const { status } = await this._testRunner.listTests([reporter], params);
157
+ return { report, status };
248
158
  }
249
159
  async runTests(params) {
250
- let result = { status: "passed" };
251
- this._queue = this._queue.then(async () => {
252
- result = await this._innerRunTests(params).catch((e) => {
253
- printInternalError(e);
254
- return { status: "failed" };
255
- });
256
- });
257
- await this._queue;
258
- return result;
259
- }
260
- async _innerRunTests(params) {
261
- await this.stopTests();
262
- const overrides = {
263
- ...this._configCLIOverrides,
264
- repeatEach: 1,
265
- retries: 0,
266
- preserveOutputDir: true,
267
- reporter: params.reporters ? params.reporters.map((r) => [r]) : void 0,
268
- use: {
269
- ...this._configCLIOverrides.use,
270
- ...params.trace === "on" ? { trace: { mode: "on", sources: false, _live: true } } : {},
271
- ...params.trace === "off" ? { trace: "off" } : {},
272
- ...params.video === "on" || params.video === "off" ? { video: params.video } : {},
273
- ...params.headed !== void 0 ? { headless: !params.headed } : {},
274
- _optionContextReuseMode: params.reuseContext ? "when-possible" : void 0,
275
- _optionConnectOptions: params.connectWsEndpoint ? { wsEndpoint: params.connectWsEndpoint } : void 0
276
- },
277
- ...params.updateSnapshots ? { updateSnapshots: params.updateSnapshots } : {},
278
- ...params.updateSourceMethod ? { updateSourceMethod: params.updateSourceMethod } : {},
279
- ...params.workers ? { workers: params.workers } : {}
280
- };
281
- if (params.trace === "on")
282
- process.env.PW_LIVE_TRACE_STACKS = "1";
283
- else
284
- process.env.PW_LIVE_TRACE_STACKS = void 0;
285
160
  const wireReporter = await this._wireReporter((e) => this._dispatchEvent("report", e));
286
- const config = await this._loadConfigOrReportError(new import_internalReporter.InternalReporter([wireReporter]), overrides);
287
- if (!config)
288
- return { status: "failed" };
289
- config.cliListOnly = false;
290
- config.cliPassWithNoTests = true;
291
- config.cliArgs = params.locations || [];
292
- config.cliGrep = params.grep;
293
- config.cliGrepInvert = params.grepInvert;
294
- config.cliProjectFilter = params.projects?.length ? params.projects : void 0;
295
- config.preOnlyTestFilters = [];
296
- if (params.testIds) {
297
- const testIdSet = new Set(params.testIds);
298
- config.preOnlyTestFilters.push((test) => testIdSet.has(test.id));
299
- }
300
- const configReporters = await (0, import_reporters.createReporters)(config, "test", true);
301
- const reporter = new import_internalReporter.InternalReporter([...configReporters, wireReporter]);
302
- const stop = new import_utils.ManualPromise();
303
- const tasks = [
304
- (0, import_tasks.createApplyRebaselinesTask)(),
305
- (0, import_tasks.createLoadTask)("out-of-process", { filterOnly: true, failOnLoadErrors: false, doNotRunDepsOutsideProjectFilter: true }),
306
- ...(0, import_tasks.createRunTestsTasks)(config)
307
- ];
308
- const run = (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), tasks, 0, stop).then(async (status) => {
309
- this._testRun = void 0;
310
- return status;
311
- });
312
- this._testRun = { run, stop };
313
- return { status: await run };
161
+ const { status } = await this._testRunner.runTests([wireReporter], params);
162
+ return { status };
163
+ }
164
+ async resumeAfterStepError(params) {
165
+ await this._testRunner.resumeAfterStepError(params);
314
166
  }
315
167
  async watch(params) {
316
- this._watchedTestDependencies = /* @__PURE__ */ new Set();
317
- for (const fileName of params.fileNames) {
318
- this._watchedTestDependencies.add(fileName);
319
- (0, import_compilationCache.dependenciesForTestFile)(fileName).forEach((file) => this._watchedTestDependencies.add(file));
320
- }
321
- await this._updateWatcher(true);
168
+ await this._testRunner.watch(params);
322
169
  }
323
170
  async findRelatedTestFiles(params) {
324
- const errorReporter = (0, import_reporters.createErrorCollectingReporter)(import_base.internalScreen);
325
- const reporter = new import_internalReporter.InternalReporter([errorReporter]);
326
- const config = await this._loadConfigOrReportError(reporter);
327
- if (!config)
328
- return { errors: errorReporter.errors(), testFiles: [] };
329
- const status = await (0, import_tasks.runTasks)(new import_tasks.TestRun(config, reporter), [
330
- (0, import_tasks.createLoadTask)("out-of-process", { failOnLoadErrors: true, filterOnly: false, populateDependencies: true })
331
- ]);
332
- if (status !== "passed")
333
- return { errors: errorReporter.errors(), testFiles: [] };
334
- return { testFiles: (0, import_compilationCache.affectedTestFiles)(params.files) };
171
+ return this._testRunner.findRelatedTestFiles(params);
335
172
  }
336
173
  async stopTests() {
337
- this._testRun?.stop?.resolve();
338
- await this._testRun?.run;
174
+ await this._testRunner.stopTests();
339
175
  }
340
176
  async _setInterceptStdio(intercept) {
341
177
  if (process.env.PWTEST_DEBUG)
@@ -362,32 +198,7 @@ class TestServerDispatcher {
362
198
  }
363
199
  }
364
200
  async closeGracefully() {
365
- (0, import_utils.gracefullyProcessExitDoNotHang)(0);
366
- }
367
- async _loadConfig(overrides) {
368
- try {
369
- const config = await (0, import_configLoader.loadConfig)(this._configLocation, overrides);
370
- if (!this._plugins) {
371
- (0, import_webServerPlugin.webServerPluginsForConfig)(config).forEach((p) => config.plugins.push({ factory: p }));
372
- (0, import_gitCommitInfoPlugin.addGitCommitInfoPlugin)(config);
373
- this._plugins = config.plugins || [];
374
- } else {
375
- config.plugins.splice(0, config.plugins.length, ...this._plugins);
376
- }
377
- return { config };
378
- } catch (e) {
379
- return { config: null, error: (0, import_util2.serializeError)(e) };
380
- }
381
- }
382
- async _loadConfigOrReportError(reporter, overrides) {
383
- const { config, error } = await this._loadConfig(overrides);
384
- if (config)
385
- return config;
386
- reporter.onConfigure(import_teleReceiver.baseFullConfig);
387
- reporter.onError(error);
388
- await reporter.onEnd({ status: "failed" });
389
- await reporter.onExit();
390
- return null;
201
+ await this._testRunner.closeGracefully();
391
202
  }
392
203
  }
393
204
  async function runUIMode(configFile, configCLIOverrides, options) {
@@ -448,39 +259,10 @@ function chunkToPayload(type, chunk) {
448
259
  return { type, buffer: chunk.toString("base64") };
449
260
  return { type, text: chunk };
450
261
  }
451
- function hasSomeBrowsers() {
452
- for (const browserName of ["chromium", "webkit", "firefox"]) {
453
- try {
454
- import_server.registry.findExecutable(browserName).executablePathOrDie("javascript");
455
- return true;
456
- } catch {
457
- }
458
- }
459
- return false;
460
- }
461
- async function installBrowsers() {
462
- const executables = import_server.registry.defaultExecutables();
463
- await import_server.registry.install(executables, false);
464
- }
465
- function printInternalError(e) {
466
- console.error("Internal error:", e);
467
- }
468
- async function resolveCtDirs(config) {
469
- const use = config.config.projects[0].use;
470
- const relativeTemplateDir = use.ctTemplateDir || "playwright";
471
- const templateDir = await import_fs.default.promises.realpath(import_path.default.normalize(import_path.default.join(config.configDir, relativeTemplateDir))).catch(() => void 0);
472
- if (!templateDir)
473
- return null;
474
- const outDir = use.ctCacheDir ? import_path.default.resolve(config.configDir, use.ctCacheDir) : import_path.default.resolve(templateDir, ".cache");
475
- return {
476
- outDir,
477
- templateDir
478
- };
479
- }
480
262
  // Annotate the CommonJS export names for ESM import in node:
481
263
  0 && (module.exports = {
264
+ TestRunnerEvent,
482
265
  TestServerDispatcher,
483
- resolveCtDirs,
484
266
  runTestServer,
485
267
  runUIMode
486
268
  });
@@ -31,6 +31,7 @@ __export(watchMode_exports, {
31
31
  runWatchModeLoop: () => runWatchModeLoop
32
32
  });
33
33
  module.exports = __toCommonJS(watchMode_exports);
34
+ var import_fs = __toESM(require("fs"));
34
35
  var import_path = __toESM(require("path"));
35
36
  var import_readline = __toESM(require("readline"));
36
37
  var import_stream = require("stream");
@@ -42,6 +43,8 @@ var import_utilsBundle = require("../utilsBundle");
42
43
  var import_testServer = require("./testServer");
43
44
  var import_teleSuiteUpdater = require("../isomorphic/teleSuiteUpdater");
44
45
  var import_testServerConnection = require("../isomorphic/testServerConnection");
46
+ var import_util = require("../util");
47
+ var import_babelBundle = require("../transform/babelBundle");
45
48
  class InMemoryTransport extends import_stream.EventEmitter {
46
49
  constructor(send) {
47
50
  super();
@@ -113,7 +116,37 @@ async function runWatchModeLoop(configLocation, initialOptions) {
113
116
  });
114
117
  });
115
118
  testServerConnection.onReport((report2) => teleSuiteUpdater.processTestReportEvent(report2));
116
- await testServerConnection.initialize({ interceptStdio: false, watchTestDirs: true, populateDependenciesOnList: true });
119
+ testServerConnection.onRecoverFromStepError(({ stepId, message, location }) => {
120
+ process.stdout.write(`
121
+ Test error occurred.
122
+ `);
123
+ process.stdout.write("\n" + createErrorCodeframe(message, location) + "\n");
124
+ process.stdout.write(`
125
+ ${import_utils2.colors.dim("Try recovering from the error. Press")} ${import_utils2.colors.bold("c")} ${import_utils2.colors.dim("to continue or")} ${import_utils2.colors.bold("t")} ${import_utils2.colors.dim("to throw the error")}
126
+ `);
127
+ readKeyPress((text) => {
128
+ if (text === "c") {
129
+ process.stdout.write(`
130
+ ${import_utils2.colors.dim("Continuing after recovery...")}
131
+ `);
132
+ testServerConnection.resumeAfterStepError({ stepId, status: "recovered", value: void 0 }).catch(() => {
133
+ });
134
+ } else if (text === "t") {
135
+ process.stdout.write(`
136
+ ${import_utils2.colors.dim("Throwing error...")}
137
+ `);
138
+ testServerConnection.resumeAfterStepError({ stepId, status: "failed" }).catch(() => {
139
+ });
140
+ }
141
+ return text;
142
+ });
143
+ });
144
+ await testServerConnection.initialize({
145
+ interceptStdio: false,
146
+ watchTestDirs: true,
147
+ populateDependenciesOnList: true,
148
+ recoverFromStepErrors: !process.env.PWTEST_RECOVERY_DISABLED
149
+ });
117
150
  await testServerConnection.runGlobalSetup({});
118
151
  const { report } = await testServerConnection.listTests({});
119
152
  teleSuiteUpdater.processListReport(report);
@@ -385,6 +418,29 @@ async function toggleShowBrowser() {
385
418
  `);
386
419
  }
387
420
  }
421
+ function createErrorCodeframe(message, location) {
422
+ let source;
423
+ try {
424
+ source = import_fs.default.readFileSync(location.file, "utf-8") + "\n//";
425
+ } catch (e) {
426
+ return;
427
+ }
428
+ return (0, import_babelBundle.codeFrameColumns)(
429
+ source,
430
+ {
431
+ start: {
432
+ line: location.line,
433
+ column: location.column
434
+ }
435
+ },
436
+ {
437
+ highlightCode: true,
438
+ linesAbove: 5,
439
+ linesBelow: 5,
440
+ message: (0, import_util.stripAnsiEscapes)(message).split("\n")[0] || void 0
441
+ }
442
+ );
443
+ }
388
444
  // Annotate the CommonJS export names for ESM import in node:
389
445
  0 && (module.exports = {
390
446
  runWatchModeLoop
@@ -39,7 +39,7 @@ var import_ipc = require("../common/ipc");
39
39
  var import_folders = require("../isomorphic/folders");
40
40
  let lastWorkerIndex = 0;
41
41
  class WorkerHost extends import_processHost.ProcessHost {
42
- constructor(testGroup, parallelIndex, config, extraEnv, outputDir) {
42
+ constructor(testGroup, parallelIndex, config, recoverFromStepErrors, extraEnv, outputDir) {
43
43
  const workerIndex = lastWorkerIndex++;
44
44
  super(require.resolve("../worker/workerMain.js"), `worker-${workerIndex}`, {
45
45
  ...extraEnv,
@@ -56,7 +56,8 @@ class WorkerHost extends import_processHost.ProcessHost {
56
56
  repeatEachIndex: testGroup.repeatEachIndex,
57
57
  projectId: testGroup.projectId,
58
58
  config,
59
- artifactsDir: import_path.default.join(outputDir, (0, import_folders.artifactsFolderName)(workerIndex))
59
+ artifactsDir: import_path.default.join(outputDir, (0, import_folders.artifactsFolderName)(workerIndex)),
60
+ recoverFromStepErrors
60
61
  };
61
62
  }
62
63
  async start() {
@@ -77,6 +78,9 @@ class WorkerHost extends import_processHost.ProcessHost {
77
78
  runTestGroup(runPayload) {
78
79
  this.sendMessageNoReply({ method: "runTestGroup", params: runPayload });
79
80
  }
81
+ resumeAfterStepError(result) {
82
+ this.sendMessageNoReply({ method: "resumeAfterStepError", params: result });
83
+ }
80
84
  hash() {
81
85
  return this._hash;
82
86
  }
package/lib/util.js CHANGED
@@ -56,7 +56,6 @@ __export(util_exports, {
56
56
  resolveReporterOutputPath: () => resolveReporterOutputPath,
57
57
  sanitizeFilePathBeforeExtension: () => sanitizeFilePathBeforeExtension,
58
58
  serializeError: () => serializeError,
59
- stepTitle: () => stepTitle,
60
59
  stripAnsiEscapes: () => stripAnsiEscapes,
61
60
  trimLongString: () => trimLongString,
62
61
  windowsFilesystemFriendlyLength: () => windowsFilesystemFriendlyLength
@@ -374,23 +373,6 @@ const ansiRegex = new RegExp("([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*
374
373
  function stripAnsiEscapes(str) {
375
374
  return str.replace(ansiRegex, "");
376
375
  }
377
- function stepTitle(category, title) {
378
- switch (category) {
379
- case "fixture":
380
- return `Fixture ${(0, import_utils.escapeWithQuotes)(title, '"')}`;
381
- case "expect":
382
- return `Expect ${(0, import_utils.escapeWithQuotes)(title, '"')}`;
383
- case "test.step":
384
- return title;
385
- case "test.attach":
386
- return `Attach ${(0, import_utils.escapeWithQuotes)(title, '"')}`;
387
- case "hook":
388
- case "pw:api":
389
- return title;
390
- default:
391
- return `[${category}] ${title}`;
392
- }
393
- }
394
376
  async function loadTestFilterFile(filePath) {
395
377
  try {
396
378
  const data = JSON.parse(await import_fs.default.promises.readFile(filePath, "utf8"));
@@ -437,7 +419,6 @@ async function loadTestFilterFile(filePath) {
437
419
  resolveReporterOutputPath,
438
420
  sanitizeFilePathBeforeExtension,
439
421
  serializeError,
440
- stepTitle,
441
422
  stripAnsiEscapes,
442
423
  trimLongString,
443
424
  windowsFilesystemFriendlyLength
@@ -35,7 +35,7 @@ class Fixture {
35
35
  const isUserFixture = this.registration.location && (0, import_util.filterStackFile)(this.registration.location.file);
36
36
  const title = this.registration.customTitle || this.registration.name;
37
37
  const location = isUserFixture ? this.registration.location : void 0;
38
- this._stepInfo = { title, category: "fixture", location };
38
+ this._stepInfo = { title: `Fixture ${(0, import_utils.escapeWithQuotes)(title, '"')}`, category: "fixture", location };
39
39
  if (this.registration.box)
40
40
  this._stepInfo.visibility = isUserFixture ? "hidden" : "internal";
41
41
  this._setupDescription = {
@@ -43,7 +43,7 @@ var import_testTracing = require("./testTracing");
43
43
  var import_util2 = require("./util");
44
44
  var import_transform = require("../transform/transform");
45
45
  class TestInfoImpl {
46
- constructor(configInternal, projectInternal, workerParams, test, retry, onStepBegin, onStepEnd, onAttach) {
46
+ constructor(configInternal, projectInternal, workerParams, test, retry, onStepBegin, onStepRecoverFromError, onStepEnd, onAttach) {
47
47
  this._snapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
48
48
  this._ariaSnapshotNames = { lastAnonymousSnapshotIndex: 0, lastNamedSnapshotIndex: {} };
49
49
  this._wasInterrupted = false;
@@ -61,6 +61,7 @@ class TestInfoImpl {
61
61
  this.errors = [];
62
62
  this.testId = test?.id ?? "";
63
63
  this._onStepBegin = onStepBegin;
64
+ this._onStepRecoverFromError = onStepRecoverFromError;
64
65
  this._onStepEnd = onStepEnd;
65
66
  this._onAttach = onAttach;
66
67
  this._startTime = (0, import_utils.monotonicTime)();
@@ -84,6 +85,7 @@ class TestInfoImpl {
84
85
  this.fn = test?.fn ?? (() => {
85
86
  });
86
87
  this.expectedStatus = test?.expectedStatus ?? "skipped";
88
+ this._recoverFromStepErrorResults = workerParams.recoverFromStepErrors ? /* @__PURE__ */ new Map() : void 0;
87
89
  this._timeoutManager = new import_timeoutManager.TimeoutManager(this.project.timeout);
88
90
  if (configInternal.configCLIOverrides.debug)
89
91
  this._setDebugMode();
@@ -202,6 +204,22 @@ class TestInfoImpl {
202
204
  steps: [],
203
205
  attachmentIndices: [],
204
206
  info: new TestStepInfoImpl(this, stepId, data.title, parentStep?.info),
207
+ recoverFromStepError: async (error) => {
208
+ if (!this._recoverFromStepErrorResults)
209
+ return { stepId, status: "failed" };
210
+ const payload = {
211
+ testId: this.testId,
212
+ stepId,
213
+ error: (0, import_util.serializeError)(error)
214
+ };
215
+ this._onStepRecoverFromError(payload);
216
+ const recoveryPromise = new import_utils.ManualPromise();
217
+ this._recoverFromStepErrorResults.set(stepId, recoveryPromise);
218
+ const recoveryResult = await recoveryPromise;
219
+ if (recoveryResult.stepId !== stepId)
220
+ return { stepId, status: "failed" };
221
+ return recoveryResult;
222
+ },
205
223
  complete: (result) => {
206
224
  if (step.endWallTime)
207
225
  return;
@@ -270,6 +288,11 @@ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
270
288
  }
271
289
  return step;
272
290
  }
291
+ resumeAfterStepError(result) {
292
+ const recoveryPromise = this._recoverFromStepErrorResults?.get(result.stepId);
293
+ if (recoveryPromise)
294
+ recoveryPromise.resolve(result);
295
+ }
273
296
  _interrupt() {
274
297
  this._wasInterrupted = true;
275
298
  this._timeoutManager.interrupt();
@@ -331,7 +354,7 @@ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
331
354
  // ------------ TestInfo methods ------------
332
355
  async attach(name, options = {}) {
333
356
  const step = this._addStep({
334
- title: name,
357
+ title: `Attach ${(0, import_utils.escapeWithQuotes)(name, '"')}`,
335
358
  category: "test.attach"
336
359
  });
337
360
  this._attach(await (0, import_util.normalizeAndSaveAttachment)(this.outputPath(), name, options), step.stepId);
@@ -343,7 +366,7 @@ ${(0, import_utils.stringifyStackFrames)(step.boxedStack).join("\n")}`;
343
366
  this._stepMap.get(stepId).attachmentIndices.push(index);
344
367
  } else {
345
368
  const stepId2 = `attach@${(0, import_utils.createGuid)()}`;
346
- this._tracing.appendBeforeActionForStep({ stepId: stepId2, title: attachment.name, category: "test.attach", stack: [] });
369
+ this._tracing.appendBeforeActionForStep({ stepId: stepId2, title: `Attach ${(0, import_utils.escapeWithQuotes)(attachment.name, '"')}`, category: "test.attach", stack: [] });
347
370
  this._tracing.appendAfterActionForStep(stepId2, void 0, [attachment]);
348
371
  }
349
372
  this._onAttach({
@@ -230,7 +230,7 @@ class TestTracing {
230
230
  startTime: (0, import_utils.monotonicTime)(),
231
231
  class: "Test",
232
232
  method: options.category,
233
- title: (0, import_util.stepTitle)(options.category, options.title),
233
+ title: options.title,
234
234
  params: Object.fromEntries(Object.entries(options.params || {}).map(([name, value]) => [name, generatePreview(value)])),
235
235
  stack: options.stack,
236
236
  visibility: options.visibility