From 51cdd270805ada91e17d720d3951f4608294856a Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 28 Mar 2024 15:01:55 -0700 Subject: [PATCH] Revert public types --- packages/playwright/src/common/test.ts | 6 +- .../playwright/src/isomorphic/teleReceiver.ts | 86 ++++--------------- packages/playwright/types/testReporter.d.ts | 23 ----- .../trace-viewer/src/ui/teleSuiteUpdater.ts | 4 +- packages/trace-viewer/src/ui/uiModeView.tsx | 4 +- utils/generate_types/index.js | 4 - .../overrides-testReporter.d.ts | 23 ----- 7 files changed, 26 insertions(+), 124 deletions(-) diff --git a/packages/playwright/src/common/test.ts b/packages/playwright/src/common/test.ts index 412b4a4e19..50f547b6ee 100644 --- a/packages/playwright/src/common/test.ts +++ b/packages/playwright/src/common/test.ts @@ -22,7 +22,7 @@ import type { Annotation, FixturesWithLocation, FullProjectInternal } from './co import type { FullProject } from '../../types/test'; import type { Location } from '../../types/testReporter'; -abstract class Base { +class Base { title: string; _only = false; _requireFile: string = ''; @@ -39,7 +39,7 @@ export type Modifier = { description: string | undefined }; -export class Suite extends Base implements reporterTypes.Suite { +export class Suite extends Base { location?: Location; parent?: Suite; _use: FixturesWithLocation[] = []; @@ -68,7 +68,7 @@ export class Suite extends Base implements reporterTypes.Suite { return this._type; } - entries(): (reporterTypes.Suite | reporterTypes.TestCase)[] { + entries() { return this._entries; } diff --git a/packages/playwright/src/isomorphic/teleReceiver.ts b/packages/playwright/src/isomorphic/teleReceiver.ts index f3ef4ac1f7..69fa49649a 100644 --- a/packages/playwright/src/isomorphic/teleReceiver.ts +++ b/packages/playwright/src/isomorphic/teleReceiver.ts @@ -131,7 +131,7 @@ type TeleReporterReceiverOptions = { }; export class TeleReporterReceiver { - private _rootSuite: TeleRootSuite; + private _rootSuite: TeleSuite; private _options: TeleReporterReceiverOptions; private _reporter: Partial; private _tests = new Map(); @@ -139,13 +139,13 @@ export class TeleReporterReceiver { private _config!: reporterTypes.FullConfig; constructor(reporter: Partial, options: TeleReporterReceiverOptions) { - this._rootSuite = new TeleRootSuite(); + this._rootSuite = new TeleSuite('', 'root'); this._options = options; this._reporter = reporter; } reset() { - this._rootSuite.reset(); + this._rootSuite._entries = []; this._tests.clear(); } @@ -202,11 +202,11 @@ export class TeleReporterReceiver { private _onProject(project: JsonProject) { let projectSuite = this._options.mergeProjects ? this._rootSuite.suites.find(suite => suite.project()!.name === project.name) : undefined; if (!projectSuite) { - projectSuite = new TeleProjectSuite(project.name); + projectSuite = new TeleSuite(project.name, 'project'); this._rootSuite._addSuite(projectSuite); } // Always update project in watch mode. - (projectSuite as TeleProjectSuite)._project = this._parseProject(project); + projectSuite._project = this._parseProject(project); for (const suite of project.suites) this._mergeSuiteInto(suite, projectSuite); } @@ -339,7 +339,7 @@ export class TeleReporterReceiver { private _mergeSuiteInto(jsonSuite: JsonSuite, parent: TeleSuite): void { let targetSuite = parent.suites.find(s => s.title === jsonSuite.title); if (!targetSuite) { - targetSuite = parent.type === 'project' ? new TeleFileSuite(jsonSuite.title) : new TeleDescribeSuite(jsonSuite.title); + targetSuite = new TeleSuite(jsonSuite.title, parent.type === 'project' ? 'file' : 'describe'); parent._addSuite(targetSuite); } targetSuite.location = this._absoluteLocation(jsonSuite.location); @@ -397,23 +397,26 @@ export class TeleReporterReceiver { } } -export abstract class TeleSuite implements reporterTypes.Suite { +export class TeleSuite implements reporterTypes.Suite { title: string; - abstract location?: reporterTypes.Location; - abstract parent?: reporterTypes.Suite; + location?: reporterTypes.Location; + parent?: TeleSuite; + _entries: (TeleSuite | TeleTestCase)[] = []; _requireFile: string = ''; _timeout: number | undefined; _retries: number | undefined; + _project: TeleFullProject | undefined; _parallelMode: 'none' | 'default' | 'serial' | 'parallel' = 'none'; - readonly _type: 'root' | 'project' | 'file' | 'describe'; - _entries: (TeleSuite | TeleTestCase)[] = []; + private readonly _type: 'root' | 'project' | 'file' | 'describe'; constructor(title: string, type: 'root' | 'project' | 'file' | 'describe') { this.title = title; this._type = type; } - abstract type: 'root' | 'project' | 'file' | 'describe'; + get type() { + return this._type; + } get suites(): TeleSuite[] { return this._entries.filter(e => e.type !== 'test') as TeleSuite[]; @@ -423,7 +426,7 @@ export abstract class TeleSuite implements reporterTypes.Suite { return this._entries.filter(e => e.type === 'test') as TeleTestCase[]; } - entries(): (reporterTypes.Suite | reporterTypes.TestCase)[] { + entries() { return this._entries; } @@ -449,7 +452,9 @@ export abstract class TeleSuite implements reporterTypes.Suite { return titlePath; } - abstract project(): TeleFullProject | undefined; + project(): TeleFullProject | undefined { + return this._project ?? this.parent?.project(); + } _addTest(test: TeleTestCase) { test.parent = this; @@ -464,59 +469,6 @@ export abstract class TeleSuite implements reporterTypes.Suite { } } -export class TeleDescribeSuite extends TeleSuite implements reporterTypes.DescribeSuite { - type: 'describe' = 'describe'; - override location!: reporterTypes.Location; - override parent!: TeleDescribeSuite | TeleFileSuite; - constructor(title: string) { - super(title, 'project'); - } - override project(): TeleFullProject { - return this.parent.project()!; - } -} - -export class TeleFileSuite extends TeleSuite implements reporterTypes.FileSuite { - type: 'file' = 'file'; - override location!: reporterTypes.Location; - override parent!: TeleProjectSuite; - constructor(title: string) { - super(title, 'project'); - } - override project(): TeleFullProject { - return this.parent.project(); - } -} - -export class TeleProjectSuite extends TeleSuite implements reporterTypes.ProjectSuite { - type: 'project' = 'project'; - _project!: TeleFullProject; - override location = undefined; - override parent!: TeleRootSuite; - constructor(title: string) { - super(title, 'project'); - } - override project(): TeleFullProject { - return this._project!; - } -} - -export class TeleRootSuite extends TeleSuite implements reporterTypes.RootSuite { - type: 'root' = 'root'; - override location = undefined; - override parent = undefined; - constructor() { - super('', 'root'); - } - override project(): undefined { - return undefined; - } - - reset() { - this._entries = []; - } -} - export class TeleTestCase implements reporterTypes.TestCase { title: string; fn = () => {}; diff --git a/packages/playwright/types/testReporter.d.ts b/packages/playwright/types/testReporter.d.ts index 5d16c08305..1fb32a391e 100644 --- a/packages/playwright/types/testReporter.d.ts +++ b/packages/playwright/types/testReporter.d.ts @@ -237,29 +237,6 @@ export interface TestCase { title: string; } -export interface FileSuite extends Suite { - type: 'file'; - location: Location; - parent: Suite; -} - -export interface DescribeSuite extends Suite { - type: 'describe'; - location: Location; - parent: Suite; -} - -export interface ProjectSuite extends Suite { - type: 'project'; - location: undefined; -} - -export interface RootSuite extends Suite { - type: 'root'; - parent: undefined; - location: undefined; -} - /** * A result of a single {@link TestCase} run. */ diff --git a/packages/trace-viewer/src/ui/teleSuiteUpdater.ts b/packages/trace-viewer/src/ui/teleSuiteUpdater.ts index 762f7529d5..253ad61a13 100644 --- a/packages/trace-viewer/src/ui/teleSuiteUpdater.ts +++ b/packages/trace-viewer/src/ui/teleSuiteUpdater.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TeleReporterReceiver, TeleRootSuite } from '@testIsomorphic/teleReceiver'; +import { TeleReporterReceiver, TeleSuite } from '@testIsomorphic/teleReceiver'; import { statusEx } from '@testIsomorphic/testTree'; import type { ReporterV2 } from 'playwright/src/reporters/reporterV2'; import type * as reporterTypes from 'playwright/types/testReporter'; @@ -137,7 +137,7 @@ export class TeleSuiteUpdater { asModel(): TestModel { return { - rootSuite: this.rootSuite || new TeleRootSuite(), + rootSuite: this.rootSuite || new TeleSuite('', 'root'), config: this.config!, loadErrors: this.loadErrors, progress: this.progress, diff --git a/packages/trace-viewer/src/ui/uiModeView.tsx b/packages/trace-viewer/src/ui/uiModeView.tsx index fc5d41de09..a4d53f11b0 100644 --- a/packages/trace-viewer/src/ui/uiModeView.tsx +++ b/packages/trace-viewer/src/ui/uiModeView.tsx @@ -17,7 +17,7 @@ import '@web/third_party/vscode/codicon.css'; import '@web/common.css'; import React from 'react'; -import { TeleRootSuite } from '@testIsomorphic/teleReceiver'; +import { TeleSuite } from '@testIsomorphic/teleReceiver'; import { TeleSuiteUpdater } from './teleSuiteUpdater'; import type { Progress } from './uiModeModel'; import type { TeleTestCase } from '@testIsomorphic/teleReceiver'; @@ -226,7 +226,7 @@ export const UIModeView: React.FC<{}> = ({ // Test tree is built from the model and filters. const { testTree } = React.useMemo(() => { if (!testModel) - return { testTree: new TestTree('', new TeleRootSuite(), [], projectFilters, pathSeparator) }; + return { testTree: new TestTree('', new TeleSuite('', 'root'), [], projectFilters, pathSeparator) }; const testTree = new TestTree('', testModel.rootSuite, testModel.loadErrors, projectFilters, pathSeparator); testTree.filterTree(filterText, statusFilters, runningState?.testIds); testTree.sortAndPropagateStatus(); diff --git a/utils/generate_types/index.js b/utils/generate_types/index.js index b43e726efe..e16f6df772 100644 --- a/utils/generate_types/index.js +++ b/utils/generate_types/index.js @@ -600,10 +600,6 @@ class TypesGenerator { 'JSONReportTest', 'JSONReportTestResult', 'JSONReportTestStep', - 'FileSuite', - 'DescribeSuite', - 'ProjectSuite', - 'RootSuite', ]), includeExperimental, }); diff --git a/utils/generate_types/overrides-testReporter.d.ts b/utils/generate_types/overrides-testReporter.d.ts index 876594896c..8faa956928 100644 --- a/utils/generate_types/overrides-testReporter.d.ts +++ b/utils/generate_types/overrides-testReporter.d.ts @@ -27,29 +27,6 @@ export interface TestCase { expectedStatus: TestStatus; } -export interface FileSuite extends Suite { - type: 'file'; - location: Location; - parent: Suite; -} - -export interface DescribeSuite extends Suite { - type: 'describe'; - location: Location; - parent: Suite; -} - -export interface ProjectSuite extends Suite { - type: 'project'; - location: undefined; -} - -export interface RootSuite extends Suite { - type: 'root'; - parent: undefined; - location: undefined; -} - export interface TestResult { status: TestStatus; }