@playwright/test 1.37.0-alpha-aug-2-2023 → 1.37.0-alpha-aug-3-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.
package/lib/cli.js CHANGED
@@ -169,7 +169,9 @@ async function mergeReports(reportDir, opts) {
169
169
  const configLoader = new _configLoader.ConfigLoader();
170
170
  const config = await (configFile ? configLoader.loadConfigFile(configFile) : configLoader.loadEmptyConfig(process.cwd()));
171
171
  const dir = _path.default.resolve(process.cwd(), reportDir || '');
172
- if (!(await _fs.default.promises.stat(dir)).isDirectory()) throw new Error('Directory does not exist: ' + dir);
172
+ const dirStat = await _fs.default.promises.stat(dir).catch(e => null);
173
+ if (!dirStat) throw new Error('Directory does not exist: ' + dir);
174
+ if (!dirStat.isDirectory()) throw new Error(`"${dir}" is not a directory`);
173
175
  let reporterDescriptions = resolveReporterOption(opts.reporter);
174
176
  if (!reporterDescriptions && configFile) reporterDescriptions = config.config.reporter;
175
177
  if (!reporterDescriptions) reporterDescriptions = [[_config.defaultReporter]];
@@ -10,6 +10,7 @@ var _teleReceiver = require("../isomorphic/teleReceiver");
10
10
  var _reporters = require("../runner/reporters");
11
11
  var _multiplexer = require("./multiplexer");
12
12
  var _utils = require("playwright-core/lib/utils");
13
+ var _util = require("../util");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  /**
15
16
  * Copyright (c) Microsoft Corporation.
@@ -28,13 +29,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
28
29
  */
29
30
 
30
31
  async function createMergedReport(config, dir, reporterDescriptions) {
32
+ const reporters = await (0, _reporters.createReporters)(config, 'merge', reporterDescriptions);
33
+ const multiplexer = new _multiplexer.Multiplexer(reporters);
34
+ const receiver = new _teleReceiver.TeleReporterReceiver(_path.default.sep, multiplexer, false, config.config);
35
+ let printStatus = () => {};
36
+ if (!multiplexer.printsToStdio()) {
37
+ printStatus = printStatusToStdout;
38
+ printStatus(`merging reports from ${dir}`);
39
+ }
31
40
  const shardFiles = await sortedShardFiles(dir);
32
41
  if (shardFiles.length === 0) throw new Error(`No report files found in ${dir}`);
33
- const events = await mergeEvents(dir, shardFiles);
42
+ const events = await mergeEvents(dir, shardFiles, printStatus);
34
43
  patchAttachmentPaths(events, dir);
35
- const reporters = await (0, _reporters.createReporters)(config, 'merge', reporterDescriptions);
36
- const receiver = new _teleReceiver.TeleReporterReceiver(_path.default.sep, new _multiplexer.Multiplexer(reporters), false, config.config);
37
- for (const event of events) await receiver.dispatch(event);
44
+ printStatus(`processing ${events.length} test events`);
45
+ for (const event of events) {
46
+ if (event.method === 'onEnd') printStatus(`building final report`);
47
+ await receiver.dispatch(event);
48
+ if (event.method === 'onEnd') printStatus(`finished building report`);
49
+ }
38
50
  }
39
51
  function patchAttachmentPaths(events, resourceDir) {
40
52
  for (const event of events) {
@@ -48,13 +60,15 @@ function patchAttachmentPaths(events, resourceDir) {
48
60
  function parseEvents(reportJsonl) {
49
61
  return reportJsonl.toString().split('\n').filter(line => line.length).map(line => JSON.parse(line));
50
62
  }
51
- async function extractAndParseReports(dir, shardFiles) {
63
+ async function extractAndParseReports(dir, shardFiles, printStatus) {
52
64
  const shardEvents = [];
53
65
  await _fs.default.promises.mkdir(_path.default.join(dir, 'resources'), {
54
66
  recursive: true
55
67
  });
56
68
  for (const file of shardFiles) {
57
- const zipFile = new _utils.ZipFile(_path.default.join(dir, file));
69
+ const absolutePath = _path.default.join(dir, file);
70
+ printStatus(`extracting: ${(0, _util.relativeFilePath)(absolutePath)}`);
71
+ const zipFile = new _utils.ZipFile(absolutePath);
58
72
  const entryNames = await zipFile.entries();
59
73
  for (const entryName of entryNames) {
60
74
  const content = await zipFile.read(entryName);
@@ -78,12 +92,12 @@ function findMetadata(events, file) {
78
92
  if (((_events$ = events[0]) === null || _events$ === void 0 ? void 0 : _events$.method) !== 'onBlobReportMetadata') throw new Error(`No metadata event found in ${file}`);
79
93
  return events[0].params;
80
94
  }
81
- async function mergeEvents(dir, shardReportFiles) {
95
+ async function mergeEvents(dir, shardReportFiles, printStatus) {
82
96
  const events = [];
83
97
  const configureEvents = [];
84
98
  const beginEvents = [];
85
99
  const endEvents = [];
86
- const shardEvents = await extractAndParseReports(dir, shardReportFiles);
100
+ const shardEvents = await extractAndParseReports(dir, shardReportFiles, printStatus);
87
101
  shardEvents.sort((a, b) => {
88
102
  var _a$metadata$shard$cur, _a$metadata$shard, _b$metadata$shard$cur, _b$metadata$shard;
89
103
  const shardA = (_a$metadata$shard$cur = (_a$metadata$shard = a.metadata.shard) === null || _a$metadata$shard === void 0 ? void 0 : _a$metadata$shard.current) !== null && _a$metadata$shard$cur !== void 0 ? _a$metadata$shard$cur : 0;
@@ -91,6 +105,7 @@ async function mergeEvents(dir, shardReportFiles) {
91
105
  return shardA - shardB;
92
106
  });
93
107
  const allTestIds = new Set();
108
+ printStatus(`merging events`);
94
109
  for (const {
95
110
  parsedEvents
96
111
  } of shardEvents) {
@@ -185,6 +200,9 @@ async function sortedShardFiles(dir) {
185
200
  const files = await _fs.default.promises.readdir(dir);
186
201
  return files.filter(file => file.startsWith('report-') && file.endsWith('.zip')).sort();
187
202
  }
203
+ function printStatusToStdout(message) {
204
+ process.stdout.write(`${message}\n`);
205
+ }
188
206
  class ProjectNamePatcher {
189
207
  constructor(_allTestIds, _projectNameSuffix) {
190
208
  this._testIds = new Set();
@@ -72,7 +72,7 @@ async function createReporters(config, mode, descriptions) {
72
72
  if (reporters.length && !someReporterPrintsToStdio) {
73
73
  // Add a line/dot/list-mode reporter for convenience.
74
74
  // Important to put it first, jsut in case some other reporter stalls onEnd.
75
- if (mode === 'list') reporters.unshift(new ListModeReporter());else reporters.unshift(!process.env.CI ? new _line.default({
75
+ if (mode === 'list') reporters.unshift(new ListModeReporter());else if (mode !== 'merge') reporters.unshift(!process.env.CI ? new _line.default({
76
76
  omitFailures: true
77
77
  }) : new _dot.default());
78
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/test",
3
- "version": "1.37.0-alpha-aug-2-2023",
3
+ "version": "1.37.0-alpha-aug-3-2023",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": "github:Microsoft/playwright",
6
6
  "homepage": "https://playwright.dev",
@@ -41,7 +41,7 @@
41
41
  "license": "Apache-2.0",
42
42
  "dependencies": {
43
43
  "@types/node": "*",
44
- "playwright-core": "1.37.0-alpha-aug-2-2023"
44
+ "playwright-core": "1.37.0-alpha-aug-3-2023"
45
45
  },
46
46
  "optionalDependencies": {
47
47
  "fsevents": "2.3.2"
package/types/test.d.ts CHANGED
@@ -3351,7 +3351,10 @@ export interface TestType<TestArgs extends KeyValue, WorkerArgs extends KeyValue
3351
3351
  * ```js
3352
3352
  * test('example test', async ({ page }) => {
3353
3353
  * // ...
3354
- * await test.info().attach('screenshot', { body: await page.screenshot(), contentType: 'image/png' });
3354
+ * await test.info().attach('screenshot', {
3355
+ * body: await page.screenshot(),
3356
+ * contentType: 'image/png',
3357
+ * });
3355
3358
  * });
3356
3359
  * ```
3357
3360
  *
@@ -316,7 +316,9 @@ export interface FullResult {
316
316
  *
317
317
  * ```js
318
318
  * // my-awesome-reporter.ts
319
- * import type { Reporter, FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
319
+ * import type {
320
+ * Reporter, FullConfig, Suite, TestCase, TestResult, FullResult
321
+ * } from '@playwright/test/reporter';
320
322
  *
321
323
  * class MyReporter implements Reporter {
322
324
  * constructor(options: { customOption?: string } = {}) {