Skip to content

Commit

Permalink
Display deleted and new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeAbby committed Dec 18, 2024
1 parent 089a278 commit 8856b0a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
45 changes: 36 additions & 9 deletions .github/workflows/postOrUpdateTestsReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,31 @@ export default async ({ github, context, core }) => {
}

const contents = await fs.readFile("new-test-results/vitest-report.json", "utf-8");
const prResults = JSON.parse(contents);
const pullRequestResults = JSON.parse(contents);

let fileInformation = {};
for (const [fileName, mainErrors] of Object.entries(mainResults)) {
const pullRequestErrors = prResults[fileName];
const pullRequestErrors = pullRequestResults[fileName];
if (pullRequestErrors == null) {
fileInformation[fileName] = { type: "removed" };
fileInformation[fileName] = { type: "deleted", oldCount: 0, newCount: 0 };
continue;
}

const errorCounts = {};

for (const error of pullRequestErrors) {
errorCounts[error.message] ??= { oldCount: 0, newCount: 0, firstLine: 0 };
errorCounts[error.message] ??= {
oldCount: 0,
newCount: 0,
};
errorCounts[error.message].oldCount++;
}

for (const error of mainErrors) {
errorCounts[error.message] ??= { oldCount: 0, newCount: 0, firstLine: 0 };
errorCounts[error.message] ??= {
oldCount: 0,
newCount: 0,
};
errorCounts[error.message].newCount++;
}

Expand All @@ -59,10 +65,24 @@ export default async ({ github, context, core }) => {
}
}

fileInformation[fileName] = { fixedErrors, newErrors, unfixedErrors };
fileInformation[fileName] = {
type: "in-both",
fixedErrors,
newErrors,
unfixedErrors,
};
}

const files = Object.keys(fileInformation).sort();
for (const [fileName, pullRequestResultErrors] of Object.entries(pullRequestResults)) {
fileInformation[fileName] ??= {
type: "new",
fixedErrors: 0,
newErrors: pullRequestResultErrors.length,
unfixedErrors: 0,
};
}

const files = Object.keys(fileInformation);

let reportTable = `|Changed File|Fixed Errors|New Errors|Unfixed Errors|
|-|-|-|-|
Expand All @@ -74,9 +94,16 @@ export default async ({ github, context, core }) => {
let hasChanges = false;
let noChangesInFiles = 0;
for (const file of files) {
const { fixedErrors, newErrors, unfixedErrors } = fileInformation[file];
const { type, fixedErrors, newErrors, unfixedErrors } = fileInformation[file];

if (fixedErrors === 0 && newErrors === 0) {
if (type === "deleted") {
reportTable += `|${file} - ***DELETED***|-|-|-|\n`;
hasChanges = true;
continue;
} else if (type === "new") {
reportTable += `|${file} - ***NEW***|-|${newErrors}|-|\n`;
continue;
} else if (fixedErrors === 0 && newErrors === 0) {
noChangesInFiles++;
continue;
}
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/testsReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ export default class JSONReporter implements Reporter {

for (const file of files) {
const filePath = relative(this.ctx.config.root, file.filepath);
fileToErrors[filePath] ??= [];

const errors = file.result?.errors ?? [];
const errors =
file.result?.errors?.map((error) => {
if (error.nameStr != null) {
return `${error.nameStr}: ${error.message}`;
}

return error.message;
}) ?? [];

if (errors.length > 0) {
fileToErrors[filePath] ??= [];
fileToErrors[filePath].push(...errors);
}
}
Expand Down

0 comments on commit 8856b0a

Please sign in to comment.