Skip to content
Open
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
25 changes: 24 additions & 1 deletion packages/core/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ const index = <T>(indexMap: Map<string, T[]>, key: string | undefined, ...items:
}
};

const originalFileNameFromMetadata = (metadata: ReaderContext["metadata"]): string | undefined => {
const { originalFileName } = metadata ?? {};

return typeof originalFileName === "string" && originalFileName.length > 0 ? originalFileName : undefined;
};

export const mapToObject = <K extends string | number | symbol, T = any>(map: Map<K, T>): Record<K, T> => {
const result: Record<string | number | symbol, T> = {};

Expand Down Expand Up @@ -535,6 +541,23 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {
return md5(environmentId ? `${environmentId}:${originalFileName}` : originalFileName);
}

#deduplicateTestResultId(testResult: TestResult, raw: RawTestResult, context: ReaderContext) {
const existing = this.#testResults.get(testResult.id);

if (!existing || !raw.uuid) {
return;
}

const incomingFileName = originalFileNameFromMetadata(context.metadata);
const existingFileName = originalFileNameFromMetadata(existing.sourceMetadata.metadata);

if (!incomingFileName || incomingFileName === existingFileName) {
return;
}

testResult.id = md5(`${raw.uuid}:${incomingFileName}`);
}

#indexGlobalError(error: PluginGlobalError) {
const resolvedEnvironment = this.#resolveGlobalEnvironmentIdentity(error.environment);

Expand Down Expand Up @@ -791,7 +814,7 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {

testResult.environment = environmentIdentity.name;
this.#addEnvironments([environmentIdentity]);

this.#deduplicateTestResultId(testResult, raw, context);
const parametersHash =
typeof raw.parametersHash === "string" && raw.parametersHash.length > 0
? raw.parametersHash
Expand Down
47 changes: 47 additions & 0 deletions packages/core/test/store/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,53 @@ describe("test results", () => {
expect(retries.map(({ name }) => name)).toEqual([retrySecond.name, retryFirst.name]);
});

it("keeps retry attempts with the same uuid from different result files", async () => {
const store = new DefaultAllureStore();
const latest: RawTestResult = {
uuid: "same-raw-uuid",
name: "latest broken attempt",
fullName: "sample test",
status: "broken",
start: 2000,
};
const retry: RawTestResult = {
uuid: "same-raw-uuid",
name: "older passed attempt",
fullName: "sample test",
status: "passed",
start: 1000,
};

await store.visitTestResult(latest, { readerId, metadata: { originalFileName: "latest-result.json" } });
await store.visitTestResult(retry, { readerId, metadata: { originalFileName: "retry-result.json" } });

const visibleResults = await store.allTestResults();
const allResults = await store.allTestResults({ includeRetries: true });
const retries = await store.retriesByTrId(visibleResults[0].id);
const statistic = await store.testsStatistic();

expect(allResults).toHaveLength(2);
expect(visibleResults).toEqual([
expect.objectContaining({
name: latest.name,
status: "broken",
isRetry: false,
}),
]);
expect(retries).toEqual([
expect.objectContaining({
name: retry.name,
status: "passed",
isRetry: true,
}),
]);
expect(statistic).toMatchObject({
total: 1,
retries: 1,
broken: 1,
});
});

it("should return retries only for the same retryHash and environment", async () => {
const store = new DefaultAllureStore({
environmentsConfig: {
Expand Down
Loading