From 0ac8fc24f9c19f60dd7a204af9c8ca16cf33ce75 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 28 Mar 2024 23:28:07 -0700 Subject: [PATCH] Address comments --- .../playwright/src/isomorphic/teleReceiver.ts | 24 ++++++------------- packages/playwright/src/reporters/merge.ts | 15 +++++------- packages/playwright/types/testReporter.d.ts | 6 ++--- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index d99849c1fd..879d37e010 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -341,20 +341,12 @@ export class TeleReporterReceiver { parent._addSuite(targetSuite); } targetSuite.location = this._absoluteLocation(jsonSuite.location); - if (jsonSuite.entries) { - jsonSuite.entries.forEach(e => { - if ('testId' in e) - this._mergeTestInto(e, targetSuite!); - else - this._mergeSuiteInto(e, targetSuite!); - }); - } else { - // before 1.44 - for (const jsonChildSuite of jsonSuite.suites!) - this._mergeSuiteInto(jsonChildSuite, targetSuite); - for (const jsonTest of jsonSuite.tests!) - this._mergeTestInto(jsonTest, targetSuite); - } + jsonSuite.entries.forEach(e => { + if ('testId' in e) + this._mergeTestInto(e, targetSuite!); + else + this._mergeSuiteInto(e, targetSuite!); + }); } private _mergeTestInto(jsonTest: JsonTestCase, parent: TeleSuite) { @@ -431,7 +423,7 @@ export class TeleSuite implements reporterTypes.Suite { allTests(): reporterTypes.TestCase[] { const result: reporterTypes.TestCase[] = []; const visit = (suite: reporterTypes.Suite) => { - for (const entry of [...suite.suites, ...suite.tests]) { + for (const entry of suite.entries()) { if (entry.type === 'test') result.push(entry); else @@ -457,13 +449,11 @@ export class TeleSuite implements reporterTypes.Suite { _addTest(test: TeleTestCase) { test.parent = this; this._entries.push(test); - this.tests.push(test); } _addSuite(suite: TeleSuite) { suite.parent = this; this._entries.push(suite); - this.suites.push(suite); } } diff --git a/packages/playwright/src/reporters/merge.ts b/packages/playwright/src/reporters/merge.ts index 82925710a4..ee40378f63 100644 --- a/packages/playwright/src/reporters/merge.ts +++ b/packages/playwright/src/reporters/merge.ts @@ -538,16 +538,13 @@ class BlobModernizer { _modernize_1_to_2(events: JsonEvent[]): JsonEvent[] { return events.map(event => { if (event.method === 'onProject') { - const modernizeSuite = (suite: blobV1.JsonSuite) => { - for (const child of suite.suites) - modernizeSuite(child); - (suite as any).entries = [...suite.suites, ...suite.tests]; - (suite as any).suites = undefined; - (suite as any).tests = undefined; + const modernizeSuite = (suite: blobV1.JsonSuite): JsonSuite => { + const newSuites = suite.suites.map(modernizeSuite); + const { suites, tests, ...remainder } = suite; + return { entries: [...newSuites, ...tests], ...remainder }; }; - const project = event.params.project as blobV1.JsonProject; - for (const suite of project.suites) - modernizeSuite(suite); + const project = event.params.project; + project.suites = project.suites.map(modernizeSuite); } return event; }); diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts index 539c8cef25..987d51e004 100644 --- a/packages/playwright/types/testReporter.d.ts +++ b/packages/playwright/types/testReporter.d.ts @@ -41,8 +41,8 @@ export type { FullConfig, TestStatus, FullProject } from './test'; */ export interface Suite { /** - * Returns type of the suite. The Suites form the following hierarchy: `root` -> `project` -> `file` -> `describe` -> - * ...`describe` -> `test`. + * Returns the type of the suite. The Suites form the following hierarchy: `root` -> `project` -> `file` -> `describe` + * -> ...`describe` -> `test`. */ type: 'root' | 'project' | 'file' | 'describe'; /** @@ -56,7 +56,7 @@ export interface Suite { allTests(): Array; /** - * Test cases and suites defined directly in this suite. The elements returned in their declaration order. You can + * Test cases and suites defined directly in this suite. The elements are returned in their declaration order. You can * discriminate between different entry types using * [testCase.type](https://playwright.dev/docs/api/class-testcase#test-case-type) and * [suite.type](https://playwright.dev/docs/api/class-suite#suite-type).