Skip to content

Commit

Permalink
Flaky support
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jul 18, 2024
1 parent 32bac4c commit 96bab1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/utils/getTestStatusIcon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@ import { getTestStatusIcon } from "./getTestStatusIcon";

describe("getTestStatusIcon", () => {
it("should return ✅ if all tests have passed", () => {
const tests = [{ results: [{ status: "passed" }] }] as TestCase[];
const tests = [
{ results: [{ status: "passed" }], outcome: () => "expected" },
] as TestCase[];

const result = getTestStatusIcon(tests);

expect(result).toBe("✅");
});

it("should return ⏭️ if any test has been skipped", () => {
const tests = [{ results: [{ status: "skipped" }] }] as TestCase[];
const tests = [
{ results: [{ status: "skipped" }], outcome: () => "expected" },
] as TestCase[];

const result = getTestStatusIcon(tests);

expect(result).toBe("⏭️");
expect(result).toBe("");
});

it("should return ❌ if any test has failed, interrupted, or timed out", () => {
const tests = [{ results: [{ status: "failed" }] }] as TestCase[];
const tests = [
{ results: [{ status: "failed" }], outcome: () => "expected" },
] as TestCase[];

const result = getTestStatusIcon(tests);

Expand All @@ -41,4 +47,12 @@ describe("getTestStatusIcon", () => {

expect(result).toBe("❌");
});

it("should return ⚠️ if any test is flaky", () => {
const tests = [{ results: [{}], outcome: () => "flaky" }] as TestCase[];

const result = getTestStatusIcon(tests);

expect(result).toBe("⚠️");
});
});
9 changes: 7 additions & 2 deletions src/utils/getTestStatusIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const getTestStatusIcon = (tests: TestCase[]) => {

const testOutcomes = tests.map((test) => {
const lastResult = test.results[test.results.length - 1];
const outcome = test.outcome();
if (outcome === "flaky") {
return "flaky";
}

return getTestOutcome(test, lastResult);
});

Expand All @@ -17,8 +22,8 @@ export const getTestStatusIcon = (tests: TestCase[]) => {
testOutcomes.includes("timedOut")
) {
return "❌";
} else if (testOutcomes.includes("skipped")) {
return "️";
} else if (testOutcomes.includes("flaky")) {
return "️";
}

return "✅";
Expand Down

0 comments on commit 96bab1a

Please sign in to comment.