Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(blob): split onBegin into multiple onProject events #26329

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions packages/playwright-test/src/isomorphic/teleReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ export class TeleReporterReceiver {
this._onConfigure(params.config);
return;
}
if (method === 'onProject') {
this._onProject(params.project);
return;
}
if (method === 'onBegin') {
this._onBegin(params.projects);
this._onBegin();
return;
}
if (method === 'onTestBegin') {
Expand Down Expand Up @@ -192,35 +196,36 @@ export class TeleReporterReceiver {
this._reporter.onConfigure(this._config);
}

private _onBegin(projects: JsonProject[]) {
for (const project of projects) {
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
if (!projectSuite) {
projectSuite = new TeleSuite(project.name, 'project');
this._rootSuite.suites.push(projectSuite);
projectSuite.parent = this._rootSuite;
}
const p = this._parseProject(project);
projectSuite.project = () => p;
this._mergeSuitesInto(project.suites, projectSuite);

// Remove deleted tests when listing. Empty suites will be auto-filtered
// in the UI layer.
if (this._listOnly) {
const testIds = new Set<string>();
const collectIds = (suite: JsonSuite) => {
suite.tests.map(t => t.testId).forEach(testId => testIds.add(testId));
suite.suites.forEach(collectIds);
};
project.suites.forEach(collectIds);

const filterTests = (suite: TeleSuite) => {
suite.tests = suite.tests.filter(t => testIds.has(t.id));
suite.suites.forEach(filterTests);
};
filterTests(projectSuite);
}
private _onProject(project: JsonProject) {
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
if (!projectSuite) {
projectSuite = new TeleSuite(project.name, 'project');
this._rootSuite.suites.push(projectSuite);
projectSuite.parent = this._rootSuite;
}
const p = this._parseProject(project);
projectSuite.project = () => p;
this._mergeSuitesInto(project.suites, projectSuite);

// Remove deleted tests when listing. Empty suites will be auto-filtered
// in the UI layer.
if (this._listOnly) {
const testIds = new Set<string>();
const collectIds = (suite: JsonSuite) => {
suite.tests.map(t => t.testId).forEach(testId => testIds.add(testId));
suite.suites.forEach(collectIds);
};
project.suites.forEach(collectIds);

const filterTests = (suite: TeleSuite) => {
suite.tests = suite.tests.filter(t => testIds.has(t.id));
suite.suites.forEach(filterTests);
};
filterTests(projectSuite);
}
}

private _onBegin() {
this._reporter.onBegin?.(this._rootSuite);
}

Expand Down
76 changes: 19 additions & 57 deletions packages/playwright-test/src/reporters/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async function mergeEvents(dir: string, shardReportFiles: string[], printStatus:
const stringPool = new StringInternPool();
const events: JsonEvent[] = [];
const configureEvents: JsonEvent[] = [];
const beginEvents: JsonEvent[] = [];
const projectEvents: JsonEvent[] = [];
const endEvents: JsonEvent[] = [];

const blobs = await extractAndParseReports(dir, shardReportFiles, stringPool, printStatus);
Expand Down Expand Up @@ -158,15 +158,22 @@ async function mergeEvents(dir: string, shardReportFiles: string[], printStatus:
for (const event of parsedEvents) {
if (event.method === 'onConfigure')
configureEvents.push(event);
else if (event.method === 'onBegin')
beginEvents.push(event);
else if (event.method === 'onProject')
projectEvents.push(event);
else if (event.method === 'onEnd')
endEvents.push(event);
else if (event.method !== 'onBlobReportMetadata')
else if (event.method !== 'onBlobReportMetadata' && event.method !== 'onBegin')
events.push(event);
}
}
return [mergeConfigureEvents(configureEvents), mergeBeginEvents(beginEvents), ...events, mergeEndEvents(endEvents), { method: 'onExit', params: undefined }];
return [
mergeConfigureEvents(configureEvents),
...projectEvents,
{ method: 'onBegin', params: undefined },
...events,
mergeEndEvents(endEvents),
{ method: 'onExit', params: undefined },
];
}

function mergeConfigureEvents(configureEvents: JsonEvent[]): JsonEvent {
Expand Down Expand Up @@ -194,28 +201,6 @@ function mergeConfigureEvents(configureEvents: JsonEvent[]): JsonEvent {
};
}

function mergeBeginEvents(beginEvents: JsonEvent[]): JsonEvent {
if (!beginEvents.length)
throw new Error('No begin events found');
const projects: JsonProject[] = [];
for (const event of beginEvents) {
const shardProjects: JsonProject[] = event.params.projects;
for (const shardProject of shardProjects) {
const mergedProject = projects.find(p => p.id === shardProject.id);
if (!mergedProject)
projects.push(shardProject);
else
mergeJsonSuites(shardProject.suites, mergedProject);
}
}
return {
method: 'onBegin',
params: {
projects,
}
};
}

function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig {
return {
...to,
Expand All @@ -230,18 +215,6 @@ function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig {
};
}

function mergeJsonSuites(jsonSuites: JsonSuite[], parent: JsonSuite | JsonProject) {
for (const jsonSuite of jsonSuites) {
const existingSuite = parent.suites.find(s => s.title === jsonSuite.title);
if (!existingSuite) {
parent.suites.push(jsonSuite);
} else {
mergeJsonSuites(jsonSuite.suites, existingSuite);
existingSuite.tests.push(...jsonSuite.tests);
}
}
}

function mergeEndEvents(endEvents: JsonEvent[]): JsonEvent {
const result: FullResult = { status: 'passed' };
for (const event of endEvents) {
Expand Down Expand Up @@ -278,8 +251,8 @@ class IdsPatcher {
for (const event of events) {
const { method, params } = event;
switch (method) {
case 'onBegin':
this._onBegin(params.config, params.projects);
case 'onProject':
this._onProject(params.project);
continue;
case 'onTestBegin':
case 'onStepBegin':
Expand All @@ -294,22 +267,11 @@ class IdsPatcher {
}
}

private _onBegin(config: JsonConfig, projects: JsonProject[]) {
const usedNames = new Set<string>();
for (const project of projects) {
project.metadata = project.metadata ?? {};
project.metadata.reportName = this._reportName;
for (let i = 0; i < projects.length; ++i) {
const candidate = (project.name + this._salt) + (i ? i : '');
if (usedNames.has(candidate))
continue;
project.id = candidate;
usedNames.add(candidate);
break;
}
}
for (const project of projects)
project.suites.forEach(suite => this._updateTestIds(suite));
private _onProject(project: JsonProject) {
project.metadata = project.metadata ?? {};
project.metadata.reportName = this._reportName;
project.id = this._stringPool.internString(project.id + this._salt);
project.suites.forEach(suite => this._updateTestIds(suite));
}

private _updateTestIds(suite: JsonSuite) {
Expand Down
4 changes: 3 additions & 1 deletion packages/playwright-test/src/reporters/teleEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export class TeleReporterEmitter implements ReporterV2 {

onBegin(suite: Suite) {
const projects = suite.suites.map(projectSuite => this._serializeProject(projectSuite));
this._messageSink({ method: 'onBegin', params: { projects } });
for (const project of projects)
dgozman marked this conversation as resolved.
Show resolved Hide resolved
this._messageSink({ method: 'onProject', params: { project } });
this._messageSink({ method: 'onBegin', params: undefined });
}

onTestBegin(test: TestCase, result: TestResult): void {
Expand Down