Skip to content

Commit

Permalink
compute global labels in the runtime constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Jan 15, 2025
1 parent 4923585 commit 83cc150
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/allure-js-commons/src/sdk/reporter/ReporterRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type Attachment,
type AttachmentOptions,
type FixtureResult,
Label,
Stage,
type StepResult,
type TestResult,
Expand Down Expand Up @@ -105,15 +106,29 @@ export class ReporterRuntime {
categories?: Category[];
environmentInfo?: EnvironmentInfo;
linkConfig?: LinkConfig;
globalLabels: ReporterRuntimeConfig["globalLabels"] = [];
globalLabels: Label[] = [];

constructor({ writer, listeners = [], environmentInfo, categories, links, globalLabels }: ReporterRuntimeConfig) {
this.writer = resolveWriter(writer);
this.notifier = new Notifier({ listeners });
this.categories = categories;
this.environmentInfo = environmentInfo;
this.linkConfig = links;
this.globalLabels = globalLabels ?? {};

if (Array.isArray(globalLabels)) {
this.globalLabels = globalLabels;
} else if (Object.keys(globalLabels as GlobalLabelsConfig).length) {
this.globalLabels = Object.entries(globalLabels as GlobalLabelsConfig).flatMap(([name, value]) => {
if (Array.isArray(value)) {
return value.map((v) => ({ name, value: v }));
}

return {
name,
value,
};
});
}
}

startScope = (): string => {
Expand Down Expand Up @@ -276,22 +291,7 @@ export class ReporterRuntime {
}
});

if (this.globalLabels && Array.isArray(this.globalLabels)) {
testResult.labels = [...this.globalLabels, ...testResult.labels];
} else if (Object.keys(this.globalLabels as GlobalLabelsConfig).length) {
const newLabels = Object.entries(this.globalLabels as GlobalLabelsConfig).flatMap(([name, value]) => {
if (Array.isArray(value)) {
return value.map((v) => ({ name, value: v }));
}

return {
name,
value,
};
});

testResult.labels = [...newLabels, ...testResult.labels];
}
testResult.labels = [...this.globalLabels, ...testResult.labels];

this.notifier.afterTestResultStop(testResult);
};
Expand Down

0 comments on commit 83cc150

Please sign in to comment.