Revert public types

This commit is contained in:
Yury Semikhatsky 2024-03-28 15:01:55 -07:00
parent 0f4002e95c
commit 51cdd27080
7 changed files with 26 additions and 124 deletions

View file

@ -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;
}

View file

@ -131,7 +131,7 @@ type TeleReporterReceiverOptions = {
};
export class TeleReporterReceiver {
private _rootSuite: TeleRootSuite;
private _rootSuite: TeleSuite;
private _options: TeleReporterReceiverOptions;
private _reporter: Partial<ReporterV2>;
private _tests = new Map<string, TeleTestCase>();
@ -139,13 +139,13 @@ export class TeleReporterReceiver {
private _config!: reporterTypes.FullConfig;
constructor(reporter: Partial<ReporterV2>, 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 = () => {};

View file

@ -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.
*/

View file

@ -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,

View file

@ -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();

View file

@ -600,10 +600,6 @@ class TypesGenerator {
'JSONReportTest',
'JSONReportTestResult',
'JSONReportTestStep',
'FileSuite',
'DescribeSuite',
'ProjectSuite',
'RootSuite',
]),
includeExperimental,
});

View file

@ -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;
}