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

This commit is contained in:
Dmitry Gozman 2023-08-07 14:33:18 -07:00 committed by GitHub
parent 27c15b705d
commit 90c765d31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 87 deletions

View file

@ -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') {
@ -192,8 +196,7 @@ export class TeleReporterReceiver {
this._reporter.onConfigure(this._config);
}
private _onBegin(projects: JsonProject[]) {
for (const project of projects) {
private _onProject(project: JsonProject) {
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
if (!projectSuite) {
projectSuite = new TeleSuite(project.name, 'project');
@ -221,6 +224,8 @@ export class TeleReporterReceiver {
filterTests(projectSuite);
}
}
private _onBegin() {
this._reporter.onBegin?.(this._rootSuite);
}

View file

@ -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);
@ -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 {
@ -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,
@ -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) {
@ -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':
@ -294,21 +267,10 @@ class IdsPatcher {
}
}
private _onBegin(config: JsonConfig, projects: JsonProject[]) {
const usedNames = new Set<string>();
for (const project of projects) {
private _onProject(project: JsonProject) {
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.id = this._stringPool.internString(project.id + this._salt);
project.suites.forEach(suite => this._updateTestIds(suite));
}

View file

@ -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)
this._messageSink({ method: 'onProject', params: { project } });
this._messageSink({ method: 'onBegin', params: undefined });
}
onTestBegin(test: TestCase, result: TestResult): void {