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
3 changes: 3 additions & 0 deletions packages/core-api/src/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ export type Statistic = DiffStatistic & {
total: number;
retries?: number;
flaky?: number;
resolutionIssue?: number;
resolutionMuted?: number;
resolutionAccepted?: number;
};
15 changes: 15 additions & 0 deletions packages/core/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,19 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {

async testsStatistic(filter?: TestResultFilter) {
const statistic: Statistic = { total: 0 };
const incrementResolution = (tr: TestResult) => {
if (tr.resolution === "issue") {
statistic.resolutionIssue = (statistic.resolutionIssue ?? 0) + 1;
}

if (tr.resolution === "muted") {
statistic.resolutionMuted = (statistic.resolutionMuted ?? 0) + 1;
}

if (tr.resolution === "accepted") {
statistic.resolutionAccepted = (statistic.resolutionAccepted ?? 0) + 1;
}
};

for (const [, tr] of this.#testResults) {
if (tr.isRetry) {
Expand All @@ -1381,6 +1394,8 @@ export class DefaultAllureStore implements AllureStore, ResultsVisitor {
statistic.new = (statistic.new ?? 0) + 1;
}

incrementResolution(tr);

if (!statistic[tr.status]) {
statistic[tr.status] = 0;
}
Expand Down
50 changes: 50 additions & 0 deletions packages/core/test/store/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,56 @@ describe("test results", () => {
await expect(target.testResultsByResolutionIssueId("SHOP-1")).resolves.toEqual([]);
});

it("should include resolution counters in test statistics", async () => {
const store = new DefaultAllureStore({
resolutionsConfig: {
links: { jira: { urlTemplate: "https://example.org/%s" } },
rules: [
{
resolution: "issue",
issue: { id: "SHOP-1", type: "jira" },
testCaseId: [md5("tc-issue")],
},
{
resolution: "muted",
comment: "muted failure",
testCaseId: [md5("tc-muted")],
},
{
resolution: "accepted",
comment: "accepted failure",
testCaseId: [md5("tc-accepted")],
},
],
},
});

await store.visitTestResult(
{ name: "issue latest", status: "failed", testId: "tc-issue", start: 1000 },
{ readerId },
);
await store.visitTestResult({ name: "issue retry", status: "failed", testId: "tc-issue", start: 0 }, { readerId });
await store.visitTestResult({ name: "muted", status: "broken", testId: "tc-muted" }, { readerId });
await store.visitTestResult({ name: "accepted", status: "failed", testId: "tc-accepted" }, { readerId });
await store.visitTestResult({ name: "passed", status: "passed", testId: "tc-passed" }, { readerId });

await expect(store.testsStatistic()).resolves.toMatchObject({
total: 4,
failed: 2,
broken: 1,
passed: 1,
resolutionIssue: 1,
resolutionMuted: 1,
resolutionAccepted: 1,
});
await expect(store.testsStatistic((tr) => tr.status === "failed")).resolves.toMatchObject({
total: 2,
failed: 2,
resolutionIssue: 1,
resolutionAccepted: 1,
});
});

it("should mark retries as isRetry", async () => {
const store = new DefaultAllureStore();
const tr1: RawTestResult = {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-api/test/summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("summary utils", () => {
testResult({ id: "n1", name: "new", status: "passed", duration: 7 }),
testResult({ id: "n2", name: "new-2", status: "failed", duration: 9 }),
];
const stats = { total: 3 } as any;
const stats = { total: 3, resolutionIssue: 1, resolutionMuted: 1, resolutionAccepted: 1 } as any;
const historyReadHistory = vi.fn().mockResolvedValue([{ branch: "main" }]);
const history = { readHistory: historyReadHistory } as unknown as AllureHistory;
const store = {
Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-awesome/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ const statisticByTestResults = async (
): Promise<Statistic> => {
const statistic: Statistic = { total: 0 };
const related = await store.relatedByTestResultIds(testResults.map(({ id }) => id));
const incrementResolution = (testResult: (typeof testResults)[number]) => {
if (testResult.resolution === "issue") {
statistic.resolutionIssue = (statistic.resolutionIssue ?? 0) + 1;
}

if (testResult.resolution === "muted") {
statistic.resolutionMuted = (statistic.resolutionMuted ?? 0) + 1;
}

if (testResult.resolution === "accepted") {
statistic.resolutionAccepted = (statistic.resolutionAccepted ?? 0) + 1;
}
};

for (const testResult of testResults) {
if (testResult.isRetry) {
Expand All @@ -59,6 +72,8 @@ const statisticByTestResults = async (
if (testResult.transition === "new") {
statistic.new = (statistic.new ?? 0) + 1;
}

incrementResolution(testResult);
}

return statistic;
Expand Down
31 changes: 25 additions & 6 deletions packages/plugin-awesome/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const require = createRequire(import.meta.url);

// duplicated the code from core to avoid circular dependency
export const getTestResultsStats = (trs: TestResult[], filter: (tr: TestResult) => boolean = () => true) => {
const trsToProcess = trs.filter(filter);
const trsToProcess = trs.filter((tr) => !tr.isRetry && filter(tr));

return trsToProcess.reduce(
(acc, test) => {
Expand All @@ -31,6 +31,18 @@ export const getTestResultsStats = (trs: TestResult[], filter: (tr: TestResult)

acc[test.status]!++;

if (test.resolution === "issue") {
acc.resolutionIssue = (acc.resolutionIssue ?? 0) + 1;
}

if (test.resolution === "muted") {
acc.resolutionMuted = (acc.resolutionMuted ?? 0) + 1;
}

if (test.resolution === "accepted") {
acc.resolutionAccepted = (acc.resolutionAccepted ?? 0) + 1;
}

return acc;
},
{ total: trsToProcess.length } as Statistic,
Expand Down Expand Up @@ -413,7 +425,8 @@ describe("plugin", () => {
const stagingTestResult = {
id: "tr-staging",
name: "staging test",
status: "passed",
status: "failed",
resolution: "accepted",
environment: "staging",
labels: [],
parameters: [],
Expand Down Expand Up @@ -494,11 +507,13 @@ describe("plugin", () => {

expect(JSON.parse(addedFiles.get("widgets/statistic.json")!.toString("utf-8"))).toEqual({
total: 1,
passed: 1,
failed: 1,
resolutionAccepted: 1,
});
expect(JSON.parse(addedFiles.get("widgets/staging/statistic.json")!.toString("utf-8"))).toEqual({
total: 1,
passed: 1,
failed: 1,
resolutionAccepted: 1,
});
expect(JSON.parse(addedFiles.get("widgets/default/statistic.json")!.toString("utf-8"))).toEqual({
total: 0,
Expand All @@ -519,7 +534,8 @@ describe("plugin", () => {
const qaATestResult = {
id: "tr-qa-a",
name: "qa a test",
status: "passed",
status: "broken",
resolution: "muted",
environment: "QA",
labels: [],
parameters: [],
Expand All @@ -532,6 +548,7 @@ describe("plugin", () => {
id: "tr-qa-b",
name: "qa b test",
status: "failed",
resolution: "issue",
environment: "QA",
labels: [],
parameters: [],
Expand Down Expand Up @@ -620,11 +637,13 @@ describe("plugin", () => {
]);
expect(JSON.parse(addedFiles.get("widgets/qa_a/statistic.json")!.toString("utf-8"))).toEqual({
total: 1,
passed: 1,
broken: 1,
resolutionMuted: 1,
});
expect(JSON.parse(addedFiles.get("widgets/qa_b/statistic.json")!.toString("utf-8"))).toEqual({
total: 1,
failed: 1,
resolutionIssue: 1,
});
expect(store.environmentIdByTrId).toHaveBeenCalledWith("tr-qa-a");
expect(store.environmentIdByTrId).toHaveBeenCalledWith("tr-qa-b");
Expand Down
Loading