@playwright/test 1.34.0-alpha-may-5-2023 → 1.34.0-alpha-may-7-2023

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.
@@ -173,7 +173,7 @@ const kPlaywrightInternalPrefix = _path.default.resolve(__dirname, '../../../pla
173
173
  const kPlaywrightCoveragePrefix = _path.default.resolve(__dirname, '../../../../tests/config/coverage.js');
174
174
  function belongsToNodeModules(file) {
175
175
  if (file.includes(`${_path.default.sep}node_modules${_path.default.sep}`)) return true;
176
- if (file.startsWith(kPlaywrightInternalPrefix)) return true;
177
- if (file.startsWith(kPlaywrightCoveragePrefix)) return true;
176
+ if (file.startsWith(kPlaywrightInternalPrefix) && file.endsWith('.js')) return true;
177
+ if (file.startsWith(kPlaywrightCoveragePrefix) && file.endsWith('.js')) return true;
178
178
  return false;
179
179
  }
@@ -154,7 +154,9 @@ class FullProjectInternal {
154
154
  grep: takeFirst(projectConfig.grep, config.grep, defaultGrep),
155
155
  grepInvert: takeFirst(projectConfig.grepInvert, config.grepInvert, null),
156
156
  outputDir: takeFirst(configCLIOverrides.outputDir, pathResolve(configDir, projectConfig.outputDir), pathResolve(configDir, config.outputDir), _path.default.join(throwawayArtifactsPath, 'test-results')),
157
- repeatEach: takeFirst(configCLIOverrides.repeatEach, projectConfig.repeatEach, config.repeatEach, 1),
157
+ // Note: we either apply the cli override for repeatEach or not, depending on whether the
158
+ // project is top-level vs dependency. See collectProjectsAndTestFiles in loadUtils.
159
+ repeatEach: takeFirst(projectConfig.repeatEach, config.repeatEach, 1),
158
160
  retries: takeFirst(configCLIOverrides.retries, projectConfig.retries, config.retries, 0),
159
161
  metadata: takeFirst(projectConfig.metadata, config.metadata, undefined),
160
162
  name: takeFirst(projectConfig.name, config.name, ''),
package/lib/index.js CHANGED
@@ -431,15 +431,17 @@ const playwrightFixtures = {
431
431
  }, use) => {
432
432
  let artifactsRecorder;
433
433
  const csiListener = {
434
- onApiCallBegin: (apiCall, stackTrace, wallTime, userData) => {
434
+ onApiCallBegin: (apiName, params, stackTrace, wallTime, userData) => {
435
435
  const testInfo = (0, _globals.currentTestInfo)();
436
- if (!testInfo || apiCall.startsWith('expect.') || apiCall.includes('setTestIdAttribute')) return {
436
+ if (!testInfo || apiName.startsWith('expect.') || apiName.includes('setTestIdAttribute')) return {
437
437
  userObject: null
438
438
  };
439
439
  const step = testInfo._addStep({
440
440
  location: stackTrace === null || stackTrace === void 0 ? void 0 : stackTrace.frames[0],
441
441
  category: 'pw:api',
442
- title: apiCall,
442
+ title: renderApiCall(apiName, params),
443
+ apiName,
444
+ params,
443
445
  wallTime,
444
446
  laxParent: true
445
447
  });
@@ -911,6 +913,27 @@ class ArtifactsRecorder {
911
913
  }
912
914
  }
913
915
  }
916
+ const paramsToRender = ['url', 'selector', 'text', 'key'];
917
+ function renderApiCall(apiName, params) {
918
+ const paramsArray = [];
919
+ if (params) {
920
+ for (const name of paramsToRender) {
921
+ if (!(name in params)) continue;
922
+ let value;
923
+ if (name === 'selector' && (0, _utils.isString)(params[name]) && params[name].startsWith('internal:')) {
924
+ const getter = (0, _utils.asLocator)('javascript', params[name], false, true);
925
+ apiName = apiName.replace(/^locator\./, 'locator.' + getter + '.');
926
+ apiName = apiName.replace(/^page\./, 'page.' + getter + '.');
927
+ apiName = apiName.replace(/^frame\./, 'frame.' + getter + '.');
928
+ } else {
929
+ value = params[name];
930
+ paramsArray.push(value);
931
+ }
932
+ }
933
+ }
934
+ const paramsText = paramsArray.length ? '(' + paramsArray.join(', ') + ')' : '';
935
+ return apiName + paramsText;
936
+ }
914
937
  const test = _baseTest.extend(playwrightFixtures);
915
938
  exports.test = test;
916
939
  var _default = test;
@@ -40,7 +40,6 @@ var _expectBundle = require("../common/expectBundle");
40
40
  // Format substring but do not enclose in double quote marks.
41
41
  // The replacement is compatible with pretty-format package.
42
42
  const printSubstring = val => val.replace(/"|\\/g, '\\$&');
43
- let lastCallId = 0;
44
43
  const printReceivedStringContainExpectedSubstring = (received, start, length // not end
45
44
  ) => (0, _expectBundle.RECEIVED_COLOR)('"' + printSubstring(received.slice(0, start)) + (0, _expectBundle.INVERTED_COLOR)(printSubstring(received.slice(start, start + length))) + printSubstring(received.slice(start + length)) + '"');
46
45
  exports.printReceivedStringContainExpectedSubstring = printReceivedStringContainExpectedSubstring;
@@ -170,16 +169,15 @@ class ExpectMetaInfoProxyHandler {
170
169
  const argsSuffix = computeArgsSuffix(matcherName, args);
171
170
  const defaultTitle = `expect${this._info.isPoll ? '.poll' : ''}${this._info.isSoft ? '.soft' : ''}${this._info.isNot ? '.not' : ''}.${matcherName}${argsSuffix}`;
172
171
  const wallTime = Date.now();
173
- const initialAttachments = new Set(testInfo.attachments.slice());
174
172
  const step = testInfo._addStep({
175
173
  location: stackFrames[0],
176
174
  category: 'expect',
177
175
  title: (0, _util.trimLongString)(customMessage || defaultTitle, 1024),
176
+ params: args[0] ? {
177
+ expected: args[0]
178
+ } : undefined,
178
179
  wallTime
179
180
  });
180
- const generateTraceEvent = matcherName !== 'poll' && matcherName !== 'toPass';
181
- const callId = ++lastCallId;
182
- if (generateTraceEvent) testInfo._traceEvents.push((0, _utils.createBeforeActionTraceEventForExpect)(`expect@${callId}`, defaultTitle, wallTime, args[0], stackFrames));
183
181
  const reportStepError = jestError => {
184
182
  const message = jestError.message;
185
183
  if (customMessage) {
@@ -196,21 +194,12 @@ class ExpectMetaInfoProxyHandler {
196
194
  jestError.stack = jestError.name + ': ' + newMessage + '\n' + (0, _util.stringifyStackFrames)(stackFrames).join('\n');
197
195
  }
198
196
  const serializerError = (0, _util.serializeError)(jestError);
199
- if (generateTraceEvent) {
200
- const error = {
201
- name: jestError.name,
202
- message: jestError.message,
203
- stack: jestError.stack
204
- };
205
- testInfo._traceEvents.push((0, _utils.createAfterActionTraceEventForExpect)(`expect@${callId}`, serializeAttachments(testInfo.attachments, initialAttachments), error));
206
- }
207
197
  step.complete({
208
198
  error: serializerError
209
199
  });
210
200
  if (this._info.isSoft) testInfo._failWithError(serializerError, false /* isHardError */);else throw jestError;
211
201
  };
212
202
  const finalizer = () => {
213
- if (generateTraceEvent) testInfo._traceEvents.push((0, _utils.createAfterActionTraceEventForExpect)(`expect@${callId}`, serializeAttachments(testInfo.attachments, initialAttachments)));
214
203
  step.complete({});
215
204
  };
216
205
 
@@ -278,15 +267,4 @@ function computeArgsSuffix(matcherName, args) {
278
267
  if (matcherName === 'toHaveScreenshot') value = (0, _toMatchSnapshot.toHaveScreenshotStepTitle)(...args);
279
268
  return value ? `(${value})` : '';
280
269
  }
281
- function serializeAttachments(attachments, initialAttachments) {
282
- return attachments.filter(a => !initialAttachments.has(a)).map(a => {
283
- var _a$body;
284
- return {
285
- name: a.name,
286
- contentType: a.contentType,
287
- path: a.path,
288
- body: (_a$body = a.body) === null || _a$body === void 0 ? void 0 : _a$body.toString('base64')
289
- };
290
- });
291
- }
292
270
  _expectBundle.expect.extend(customMatchers);
@@ -72,6 +72,12 @@ async function collectProjectsAndTestFiles(testRun, additionalFileMatcher) {
72
72
  filesToRunByProject.set(project, files);
73
73
  }
74
74
  }
75
+
76
+ // Apply overrides that are only applicable to top-level projects.
77
+ for (const [project, type] of projectClosure) {
78
+ var _project$fullConfig$c;
79
+ if (type === 'top-level') project.project.repeatEach = (_project$fullConfig$c = project.fullConfig.configCLIOverrides.repeatEach) !== null && _project$fullConfig$c !== void 0 ? _project$fullConfig$c : project.project.repeatEach;
80
+ }
75
81
  testRun.projects = [...filesToRunByProject.keys()];
76
82
  testRun.projectFiles = filesToRunByProject;
77
83
  testRun.projectType = projectClosure;
package/lib/util.js CHANGED
@@ -17,7 +17,6 @@ exports.experimentalLoaderOption = experimentalLoaderOption;
17
17
  exports.fileIsModule = fileIsModule;
18
18
  exports.filterStackTrace = filterStackTrace;
19
19
  exports.filteredStackTrace = filteredStackTrace;
20
- exports.folderIsModule = folderIsModule;
21
20
  exports.forceRegExp = forceRegExp;
22
21
  exports.formatLocation = formatLocation;
23
22
  exports.getContainedPath = getContainedPath;
@@ -70,6 +70,12 @@ class Fixture {
70
70
  return;
71
71
  }
72
72
  }
73
+
74
+ // Break the regustration function into before/after steps. Create these before/after stacks
75
+ // w/o scopes, and create single mutable step that will be converted into the after step.
76
+ const shouldGenerateStep = !this.registration.name.startsWith('_') && !this.registration.option && this.registration.scope === 'test';
77
+ let mutableStepOnStack;
78
+ let afterStep;
73
79
  let called = false;
74
80
  const useFuncStarted = new _utils.ManualPromise();
75
81
  (0, _util.debugTest)(`setup ${this.registration.name}`);
@@ -80,6 +86,14 @@ class Fixture {
80
86
  this._useFuncFinished = new _utils.ManualPromise();
81
87
  useFuncStarted.resolve();
82
88
  await this._useFuncFinished;
89
+ if (shouldGenerateStep) {
90
+ afterStep = testInfo._addStep({
91
+ wallTime: Date.now(),
92
+ title: `fixture: ${this.registration.name}`,
93
+ category: 'fixture'
94
+ }, testInfo._afterHooksStep);
95
+ mutableStepOnStack.stepId = afterStep.stepId;
96
+ }
83
97
  };
84
98
  const workerInfo = {
85
99
  config: testInfo.config,
@@ -95,13 +109,28 @@ class Fixture {
95
109
  };
96
110
  try {
97
111
  const result = _utils.zones.preserve(async () => {
98
- return await this.registration.fn(params, useFunc, info);
112
+ if (!shouldGenerateStep) return await this.registration.fn(params, useFunc, info);
113
+ await testInfo._runAsStep({
114
+ title: `fixture: ${this.registration.name}`,
115
+ category: 'fixture'
116
+ }, async step => {
117
+ mutableStepOnStack = step;
118
+ return await this.registration.fn(params, useFunc, info);
119
+ });
99
120
  });
100
121
  if (result instanceof Promise) this._selfTeardownComplete = result.catch(handleError);else this._selfTeardownComplete = Promise.resolve();
101
122
  } catch (e) {
102
123
  handleError(e);
103
124
  }
104
125
  await useFuncStarted;
126
+ if (shouldGenerateStep) {
127
+ var _mutableStepOnStack, _this$_selfTeardownCo;
128
+ (_mutableStepOnStack = mutableStepOnStack) === null || _mutableStepOnStack === void 0 ? void 0 : _mutableStepOnStack.complete({});
129
+ (_this$_selfTeardownCo = this._selfTeardownComplete) === null || _this$_selfTeardownCo === void 0 ? void 0 : _this$_selfTeardownCo.finally(() => {
130
+ var _afterStep;
131
+ (_afterStep = afterStep) === null || _afterStep === void 0 ? void 0 : _afterStep.complete({});
132
+ });
133
+ }
105
134
  testInfo._timeoutManager.setCurrentFixture(undefined);
106
135
  }
107
136
  async teardown(timeoutManager) {
@@ -57,6 +57,8 @@ class TestInfoImpl {
57
57
  this._projectInternal = void 0;
58
58
  this._configInternal = void 0;
59
59
  this._steps = [];
60
+ this._beforeHooksStep = void 0;
61
+ this._afterHooksStep = void 0;
60
62
  this.testId = void 0;
61
63
  this.repeatEachIndex = void 0;
62
64
  this.retry = void 0;
@@ -162,9 +164,10 @@ class TestInfoImpl {
162
164
  }
163
165
  }
164
166
  }
165
- _addStep(data) {
167
+ _addStep(data, parentStep) {
168
+ var _parentStep;
166
169
  const stepId = `${data.category}@${data.title}@${++this._lastStepId}`;
167
- let parentStep = _utils.zones.zoneData('stepZone', (0, _utils.captureRawStack)());
170
+ if (!parentStep) parentStep = _utils.zones.zoneData('stepZone', (0, _utils.captureRawStack)()) || undefined;
168
171
 
169
172
  // For out-of-stack calls, locate the enclosing step.
170
173
  let isLaxParent = false;
@@ -178,6 +181,7 @@ class TestInfoImpl {
178
181
  this._steps.forEach(visit);
179
182
  isLaxParent = !!parentStep;
180
183
  }
184
+ const initialAttachments = new Set(this.attachments);
181
185
  const step = {
182
186
  stepId,
183
187
  ...data,
@@ -206,6 +210,12 @@ class TestInfoImpl {
206
210
  error
207
211
  };
208
212
  this._onStepEnd(payload);
213
+ const errorForTrace = error ? {
214
+ name: '',
215
+ message: error.message || '',
216
+ stack: error.stack
217
+ } : undefined;
218
+ this._traceEvents.push((0, _utils.createAfterActionTraceEventForStep)(stepId, serializeAttachments(this.attachments, initialAttachments), errorForTrace));
209
219
  }
210
220
  };
211
221
  const parentStepList = parentStep ? parentStep.steps : this._steps;
@@ -221,10 +231,13 @@ class TestInfoImpl {
221
231
  testId: this._test.id,
222
232
  stepId,
223
233
  parentStepId: parentStep ? parentStep.stepId : undefined,
224
- ...data,
234
+ title: data.title,
235
+ category: data.category,
236
+ wallTime: data.wallTime,
225
237
  location
226
238
  };
227
239
  this._onStepBegin(payload);
240
+ this._traceEvents.push((0, _utils.createBeforeActionTraceEventForStep)(stepId, (_parentStep = parentStep) === null || _parentStep === void 0 ? void 0 : _parentStep.stepId, data.apiName || data.title, data.params, data.wallTime, data.location ? [data.location] : []));
228
241
  return step;
229
242
  }
230
243
  _interrupt() {
@@ -310,4 +323,15 @@ class TestInfoImpl {
310
323
  }
311
324
  }
312
325
  exports.TestInfoImpl = TestInfoImpl;
326
+ function serializeAttachments(attachments, initialAttachments) {
327
+ return attachments.filter(a => !initialAttachments.has(a)).map(a => {
328
+ var _a$body;
329
+ return {
330
+ name: a.name,
331
+ contentType: a.contentType,
332
+ path: a.path,
333
+ body: (_a$body = a.body) === null || _a$body === void 0 ? void 0 : _a$body.toString('base64')
334
+ };
335
+ });
336
+ }
313
337
  class SkipError extends Error {}
@@ -291,6 +291,7 @@ class WorkerMain extends _process.ProcessRunner {
291
291
  category: 'hook',
292
292
  title: 'Before Hooks'
293
293
  }, async step => {
294
+ testInfo._beforeHooksStep = step;
294
295
  // Note: wrap all preparation steps together, because failure/skip in any of them
295
296
  // prevents further setup and/or test from running.
296
297
  const beforeHooksError = await testInfo._runAndFailOnError(async () => {
@@ -371,6 +372,7 @@ class WorkerMain extends _process.ProcessRunner {
371
372
  category: 'hook',
372
373
  title: 'After Hooks'
373
374
  }, async step => {
375
+ testInfo._afterHooksStep = step;
374
376
  let firstAfterHooksError;
375
377
  await testInfo._runWithTimeout(async () => {
376
378
  // Note: do not wrap all teardown steps together, because failure in any of them
@@ -450,15 +452,14 @@ class WorkerMain extends _process.ProcessRunner {
450
452
  firstAfterHooksError = firstAfterHooksError || workerScopeError;
451
453
  });
452
454
  }
453
- const didRunTestError = await testInfo._runAndFailOnError(async () => {
454
- var _currentTestInstrumen3;
455
- return await ((_currentTestInstrumen3 = (0, _globals.currentTestInstrumentation)()) === null || _currentTestInstrumen3 === void 0 ? void 0 : _currentTestInstrumen3.didFinishTest(testInfo));
456
- });
457
- firstAfterHooksError = firstAfterHooksError || didRunTestError;
458
455
  if (firstAfterHooksError) step.complete({
459
456
  error: firstAfterHooksError
460
457
  });
461
458
  });
459
+ await testInfo._runAndFailOnError(async () => {
460
+ var _currentTestInstrumen3;
461
+ return await ((_currentTestInstrumen3 = (0, _globals.currentTestInstrumentation)()) === null || _currentTestInstrumen3 === void 0 ? void 0 : _currentTestInstrumen3.didFinishTest(testInfo));
462
+ });
462
463
  this._currentTest = null;
463
464
  (0, _globals.setCurrentTestInfo)(null);
464
465
  this.dispatchEvent('testEnd', buildTestEndPayload(testInfo));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/test",
3
- "version": "1.34.0-alpha-may-5-2023",
3
+ "version": "1.34.0-alpha-may-7-2023",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": "github:Microsoft/playwright",
6
6
  "homepage": "https://playwright.dev",
@@ -37,7 +37,7 @@
37
37
  "license": "Apache-2.0",
38
38
  "dependencies": {
39
39
  "@types/node": "*",
40
- "playwright-core": "1.34.0-alpha-may-5-2023"
40
+ "playwright-core": "1.34.0-alpha-may-7-2023"
41
41
  },
42
42
  "optionalDependencies": {
43
43
  "fsevents": "2.3.2"