Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flaky test labels for playwright projects #28980

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
9 changes: 9 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@
- name: "Z-Flaky-Test"
description: "A test is raising false alarms"
color: "ededed"
- name: "Z-Flaky-Test-Chrome"
description: "Flaky playwright test in Chrome"
color: "ededed"
- name: "Z-Flaky-Test-Firefox"
description: "Flaky playwright test in Firefox"
color: "ededed"
- name: "Z-Flaky-Test-Webkit"
description: "Flaky playwright test in Webkit"
color: "ededed"
- name: "Z-Flaky-Jest-Test"
description: "A Jest test is raising false alarms"
color: "ededed"
Expand Down
18 changes: 14 additions & 4 deletions playwright/flaky-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ type PaginationLinks = {
};

class FlakyReporter implements Reporter {
private flakes = new Set<string>();
private flakes = new Map<string, TestCase[]>();

public onTestEnd(test: TestCase): void {
const title = `${test.location.file.split("playwright/e2e/")[1]}: ${test.title}`;
if (test.outcome() === "flaky") {
this.flakes.add(title);
if (!this.flakes.has(title)) {
this.flakes.set(title, []);
}
this.flakes.get(title).push(test);
}
}

Expand Down Expand Up @@ -97,12 +100,14 @@ class FlakyReporter implements Reporter {
if (!GITHUB_TOKEN) return;

const issues = await this.getAllIssues();
for (const flake of this.flakes) {
for (const [flake, results] of this.flakes) {
const title = ISSUE_TITLE_PREFIX + "`" + flake + "`";
const existingIssue = issues.find((issue) => issue.title === title);
const headers = { Authorization: `Bearer ${GITHUB_TOKEN}` };
const body = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}`;

const labels = [LABEL, ...results.map((test) => test.parent.project()?.name).filter(Boolean)];

if (existingIssue) {
console.log(`Found issue ${existingIssue.number} for ${flake}, adding comment...`);
// Ensure that the test is open
Expand All @@ -111,6 +116,11 @@ class FlakyReporter implements Reporter {
headers,
body: JSON.stringify({ state: "open" }),
});
await fetch(`${existingIssue.url}/labels`, {
method: "POST",
headers,
body: JSON.stringify({ labels }),
});
await fetch(`${existingIssue.url}/comments`, {
method: "POST",
headers,
Expand All @@ -124,7 +134,7 @@ class FlakyReporter implements Reporter {
body: JSON.stringify({
title,
body,
labels: [LABEL],
labels: [...labels],
}),
});
}
Expand Down
Loading