chore(test runner): include projects in teleReceiver's config

This commit is contained in:
Simon Knott 2024-09-03 15:59:42 +02:00
parent 201bad75d3
commit 3c62283ef6
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
4 changed files with 30 additions and 13 deletions

View file

@ -26,14 +26,14 @@ export type JsonStackFrame = { file: string, line: number, column: number };
export type JsonStdIOType = 'stdout' | 'stderr'; export type JsonStdIOType = 'stdout' | 'stderr';
export type JsonConfig = Pick<reporterTypes.FullConfig, 'configFile' | 'globalTimeout' | 'maxFailures' | 'metadata' | 'rootDir' | 'version' | 'workers'>; export type JsonConfig = Pick<reporterTypes.FullConfig, 'configFile' | 'globalTimeout' | 'maxFailures' | 'metadata' | 'rootDir' | 'version' | 'workers'> & { projects: JsonConfigProject[] };
export type JsonPattern = { export type JsonPattern = {
s?: string; s?: string;
r?: { source: string, flags: string }; r?: { source: string, flags: string };
}; };
export type JsonProject = { export type JsonConfigProject = {
grep: JsonPattern[]; grep: JsonPattern[];
grepInvert: JsonPattern[]; grepInvert: JsonPattern[];
metadata: Metadata; metadata: Metadata;
@ -45,7 +45,6 @@ export type JsonProject = {
outputDir: string; outputDir: string;
repeatEach: number; repeatEach: number;
retries: number; retries: number;
suites: JsonSuite[];
teardown?: string; teardown?: string;
// This is relative to root dir. // This is relative to root dir.
testDir: string; testDir: string;
@ -54,6 +53,10 @@ export type JsonProject = {
timeout: number; timeout: number;
}; };
export type JsonProject = JsonConfigProject & {
suites: JsonSuite[];
};
export type JsonSuite = { export type JsonSuite = {
title: string; title: string;
location?: JsonLocation; location?: JsonLocation;
@ -304,10 +307,13 @@ export class TeleReporterReceiver {
result.quiet = this._options.configOverrides.quiet; result.quiet = this._options.configOverrides.quiet;
result.reporter = [...this._options.configOverrides.reporter]; result.reporter = [...this._options.configOverrides.reporter];
} }
return result; return {
...result,
projects: result.projects.map(p => this._parseProject(p)),
};
} }
private _parseProject(project: JsonProject): TeleFullProject { private _parseProject(project: JsonConfigProject): TeleFullProject {
return { return {
metadata: project.metadata, metadata: project.metadata,
name: project.name, name: project.name,

View file

@ -255,6 +255,7 @@ function mergeConfigureEvents(configureEvents: JsonEvent[], rootDirOverride: str
rootDir: '', rootDir: '',
version: '', version: '',
workers: 0, workers: 0,
projects: [],
}; };
for (const event of configureEvents) for (const event of configureEvents)
config = mergeConfigs(config, event.params.config); config = mergeConfigs(config, event.params.config);
@ -288,6 +289,11 @@ function mergeConfigureEvents(configureEvents: JsonEvent[], rootDirOverride: str
}; };
} }
function dedupByName<T extends { name: string }>(a: T[], b: T[]) {
const aNames = new Set(a.map(v => v.name));
return a.concat(b.filter(b => !aNames.has(b.name)));
}
function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig { function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig {
return { return {
...to, ...to,
@ -298,6 +304,7 @@ function mergeConfigs(to: JsonConfig, from: JsonConfig): JsonConfig {
actualWorkers: (to.metadata.actualWorkers || 0) + (from.metadata.actualWorkers || 0), actualWorkers: (to.metadata.actualWorkers || 0) + (from.metadata.actualWorkers || 0),
}, },
workers: to.workers + from.workers, workers: to.workers + from.workers,
projects: dedupByName(to.projects, from.projects),
}; };
} }

View file

@ -161,12 +161,12 @@ export class TeleReporterEmitter implements ReporterV2 {
rootDir: config.rootDir, rootDir: config.rootDir,
version: config.version, version: config.version,
workers: config.workers, workers: config.workers,
projects: config.projects.map(project => this._serializeConfigProject(project)),
}; };
} }
private _serializeProject(suite: reporterTypes.Suite): teleReceiver.JsonProject { private _serializeConfigProject(project: reporterTypes.FullProject): teleReceiver.JsonConfigProject {
const project = suite.project()!; return {
const report: teleReceiver.JsonProject = {
metadata: project.metadata, metadata: project.metadata,
name: project.name, name: project.name,
outputDir: this._relativePath(project.outputDir), outputDir: this._relativePath(project.outputDir),
@ -176,16 +176,20 @@ export class TeleReporterEmitter implements ReporterV2 {
testIgnore: serializeRegexPatterns(project.testIgnore), testIgnore: serializeRegexPatterns(project.testIgnore),
testMatch: serializeRegexPatterns(project.testMatch), testMatch: serializeRegexPatterns(project.testMatch),
timeout: project.timeout, timeout: project.timeout,
suites: suite.suites.map(fileSuite => {
return this._serializeSuite(fileSuite);
}),
grep: serializeRegexPatterns(project.grep), grep: serializeRegexPatterns(project.grep),
grepInvert: serializeRegexPatterns(project.grepInvert || []), grepInvert: serializeRegexPatterns(project.grepInvert || []),
dependencies: project.dependencies, dependencies: project.dependencies,
snapshotDir: this._relativePath(project.snapshotDir), snapshotDir: this._relativePath(project.snapshotDir),
teardown: project.teardown, teardown: project.teardown,
}; };
return report; }
private _serializeProject(suite: reporterTypes.Suite): teleReceiver.JsonProject {
const project = suite.project()!;
return {
...this._serializeConfigProject(project),
suites: suite.suites.map(fileSuite => this._serializeSuite(fileSuite)),
};
} }
private _serializeSuite(suite: reporterTypes.Suite): teleReceiver.JsonSuite { private _serializeSuite(suite: reporterTypes.Suite): teleReceiver.JsonSuite {

View file

@ -167,7 +167,7 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp
type: 'multiselect', type: 'multiselect',
name: 'selectedProjects', name: 'selectedProjects',
message: 'Select projects', message: 'Select projects',
choices: teleSuiteUpdater.rootSuite!.suites.map(s => s.title), choices: teleSuiteUpdater.config!.projects.map(p => p.name),
}).catch(() => ({ selectedProjects: null })); }).catch(() => ({ selectedProjects: null }));
if (!selectedProjects) if (!selectedProjects)
continue; continue;