Add flaky test labels for playwright projects (#28980)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
11a8723c73
commit
5a5db19c2c
9
.github/labels.yml
vendored
9
.github/labels.yml
vendored
@@ -235,6 +235,15 @@
|
|||||||
- name: "Z-Flaky-Test"
|
- name: "Z-Flaky-Test"
|
||||||
description: "A test is raising false alarms"
|
description: "A test is raising false alarms"
|
||||||
color: "ededed"
|
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"
|
- name: "Z-Flaky-Jest-Test"
|
||||||
description: "A Jest test is raising false alarms"
|
description: "A Jest test is raising false alarms"
|
||||||
color: "ededed"
|
color: "ededed"
|
||||||
|
|||||||
@@ -25,12 +25,15 @@ type PaginationLinks = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class FlakyReporter implements Reporter {
|
class FlakyReporter implements Reporter {
|
||||||
private flakes = new Set<string>();
|
private flakes = new Map<string, TestCase[]>();
|
||||||
|
|
||||||
public onTestEnd(test: TestCase): void {
|
public onTestEnd(test: TestCase): void {
|
||||||
const title = `${test.location.file.split("playwright/e2e/")[1]}: ${test.title}`;
|
const title = `${test.location.file.split("playwright/e2e/")[1]}: ${test.title}`;
|
||||||
if (test.outcome() === "flaky") {
|
if (test.outcome() === "flaky") {
|
||||||
this.flakes.add(title);
|
if (!this.flakes.has(title)) {
|
||||||
|
this.flakes.set(title, []);
|
||||||
|
}
|
||||||
|
this.flakes.get(title).push(test);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +100,14 @@ class FlakyReporter implements Reporter {
|
|||||||
if (!GITHUB_TOKEN) return;
|
if (!GITHUB_TOKEN) return;
|
||||||
|
|
||||||
const issues = await this.getAllIssues();
|
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 title = ISSUE_TITLE_PREFIX + "`" + flake + "`";
|
||||||
const existingIssue = issues.find((issue) => issue.title === title);
|
const existingIssue = issues.find((issue) => issue.title === title);
|
||||||
const headers = { Authorization: `Bearer ${GITHUB_TOKEN}` };
|
const headers = { Authorization: `Bearer ${GITHUB_TOKEN}` };
|
||||||
const body = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}`;
|
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) {
|
if (existingIssue) {
|
||||||
console.log(`Found issue ${existingIssue.number} for ${flake}, adding comment...`);
|
console.log(`Found issue ${existingIssue.number} for ${flake}, adding comment...`);
|
||||||
// Ensure that the test is open
|
// Ensure that the test is open
|
||||||
@@ -111,6 +116,11 @@ class FlakyReporter implements Reporter {
|
|||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ state: "open" }),
|
body: JSON.stringify({ state: "open" }),
|
||||||
});
|
});
|
||||||
|
await fetch(`${existingIssue.url}/labels`, {
|
||||||
|
method: "POST",
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify({ labels }),
|
||||||
|
});
|
||||||
await fetch(`${existingIssue.url}/comments`, {
|
await fetch(`${existingIssue.url}/comments`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers,
|
||||||
@@ -124,7 +134,7 @@ class FlakyReporter implements Reporter {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
labels: [LABEL],
|
labels: [...labels],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user