chore(blob): split onBegin into multiple onProject events (#26329)
This commit is contained in:
parent
27c15b705d
commit
90c765d31c
|
|
@ -147,8 +147,12 @@ export class TeleReporterReceiver {
|
||||||
this._onConfigure(params.config);
|
this._onConfigure(params.config);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (method === 'onProject') {
|
||||||
|
this._onProject(params.project);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (method === 'onBegin') {
|
if (method === 'onBegin') {
|
||||||
this._onBegin(params.projects);
|
this._onBegin();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (method === 'onTestBegin') {
|
if (method === 'onTestBegin') {
|
||||||
|
|
@ -192,35 +196,36 @@ export class TeleReporterReceiver {
|
||||||
this._reporter.onConfigure(this._config);
|
this._reporter.onConfigure(this._config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onBegin(projects: JsonProject[]) {
|
private _onProject(project: JsonProject) {
|
||||||
for (const project of projects) {
|
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
|
||||||
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.id === project.id);
|
if (!projectSuite) {
|
||||||
if (!projectSuite) {
|
projectSuite = new TeleSuite(project.name, 'project');
|
||||||
projectSuite = new TeleSuite(project.name, 'project');
|
this._rootSuite.suites.push(projectSuite);
|
||||||
this._rootSuite.suites.push(projectSuite);
|
projectSuite.parent = this._rootSuite;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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);
|
this._reporter.onBegin?.(this._rootSuite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ async function mergeEvents(dir: string, shardReportFiles: string[], printStatus:
|
||||||
const stringPool = new StringInternPool();
|
const stringPool = new StringInternPool();
|
||||||
const events: JsonEvent[] = [];
|
const events: JsonEvent[] = [];
|
||||||
const configureEvents: JsonEvent[] = [];
|
const configureEvents: JsonEvent[] = [];
|
||||||
const beginEvents: JsonEvent[] = [];
|
const projectEvents: JsonEvent[] = [];
|
||||||
const endEvents: JsonEvent[] = [];
|
const endEvents: JsonEvent[] = [];
|
||||||
|
|
||||||
const blobs = await extractAndParseReports(dir, shardReportFiles, stringPool, printStatus);
|
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) {
|
for (const event of parsedEvents) {
|
||||||
if (event.method === 'onConfigure')
|
if (event.method === 'onConfigure')
|
||||||
configureEvents.push(event);
|
configureEvents.push(event);
|
||||||
else if (event.method === 'onBegin')
|
else if (event.method === 'onProject')
|
||||||
beginEvents.push(event);
|
projectEvents.push(event);
|
||||||
else if (event.method === 'onEnd')
|
else if (event.method === 'onEnd')
|
||||||
endEvents.push(event);
|
endEvents.push(event);
|
||||||
else if (event.method !== 'onBlobReportMetadata')
|
else if (event.method !== 'onBlobReportMetadata' && event.method !== 'onBegin')
|
||||||
events.push(event);
|
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 {
|
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 {
|
function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig {
|
||||||
return {
|
return {
|
||||||
...to,
|
...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 {
|
function mergeEndEvents(endEvents: JsonEvent[]): JsonEvent {
|
||||||
const result: FullResult = { status: 'passed' };
|
const result: FullResult = { status: 'passed' };
|
||||||
for (const event of endEvents) {
|
for (const event of endEvents) {
|
||||||
|
|
@ -278,8 +251,8 @@ class IdsPatcher {
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
const { method, params } = event;
|
const { method, params } = event;
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'onBegin':
|
case 'onProject':
|
||||||
this._onBegin(params.config, params.projects);
|
this._onProject(params.project);
|
||||||
continue;
|
continue;
|
||||||
case 'onTestBegin':
|
case 'onTestBegin':
|
||||||
case 'onStepBegin':
|
case 'onStepBegin':
|
||||||
|
|
@ -294,22 +267,11 @@ class IdsPatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onBegin(config: JsonConfig, projects: JsonProject[]) {
|
private _onProject(project: JsonProject) {
|
||||||
const usedNames = new Set<string>();
|
project.metadata = project.metadata ?? {};
|
||||||
for (const project of projects) {
|
project.metadata.reportName = this._reportName;
|
||||||
project.metadata = project.metadata ?? {};
|
project.id = this._stringPool.internString(project.id + this._salt);
|
||||||
project.metadata.reportName = this._reportName;
|
project.suites.forEach(suite => this._updateTestIds(suite));
|
||||||
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 _updateTestIds(suite: JsonSuite) {
|
private _updateTestIds(suite: JsonSuite) {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,9 @@ export class TeleReporterEmitter implements ReporterV2 {
|
||||||
|
|
||||||
onBegin(suite: Suite) {
|
onBegin(suite: Suite) {
|
||||||
const projects = suite.suites.map(projectSuite => this._serializeProject(projectSuite));
|
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 {
|
onTestBegin(test: TestCase, result: TestResult): void {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue