Skip to content

Commit

Permalink
Refactor test result processing to parse XML into JSON and enhance ou…
Browse files Browse the repository at this point in the history
…tput formatting
  • Loading branch information
DE7924 committed Dec 23, 2024
1 parent 41bdb1b commit c6e0295
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
46 changes: 20 additions & 26 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

53 changes: 27 additions & 26 deletions src/scripts/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,36 @@ export const testing = async (
}

if (response.error && failedToReadFile == false) {
outputStr += convert.xml2json(testResults, { compact: false, spaces: 2 });
console.log(outputStr);
try {
fs.writeFileSync("src/test/json-results.json", outputStr);
} catch (error) {
setFailed(`Failed to write output to file: ${error as string}`);
}
// outputStr +=
// "<table><tr><th>File</th><th>Test Name</th><th>Line</th><th>Message</th></tr>";
const jsonResults = JSON.parse(
convert.xml2json(testResults, { compact: false, spaces: 2 }),
);

// const parser = new DOMParser();
// const doc = parser.parseFromString(testResults, "text/xml");
outputStr +=
"<table><tr><th>File</th><th>Test Name</th><th>Line</th><th>Type</th><th>Message</th></tr>";

// const testCases = doc.getElementsByTagName("testcase");
// for (let i = 0; i < testCases.length; i++) {
// const testCase = testCases[i];
// const testCaseName = testCase.getAttribute("name");
// const testCaseFailure = testCase.getElementsByTagName("failure");
// if (testCaseFailure) {
// const testCaseFile = testCase.getAttribute("file");
// const testCaseLine = testCase.getAttribute("line");
// const testCaseMessage = testCase
// .getElementsByTagName("failure")[0]
// .getAttribute("message");
// outputStr += `<tr><td>${testCaseFile}</td><td>${testCaseName}</td><td>${testCaseLine}</td><td>${testCaseMessage}</td></tr>`;
// }
// }
const testSuites = jsonResults["elements"][0]["elements"];
for (let i = 0; i < testSuites.length; i++) {

Check warning on line 61 in src/scripts/testing.ts

View workflow job for this annotation

GitHub Actions / code-quality

Expected a `for-of` loop instead of a `for` loop with this simple iteration
const testSuite = testSuites[i];
const testCases = testSuite["elements"].filter(
(element: any) => element.name === "testcase",
);
for (let j = 0; j < testCases.length; j++) {

Check warning on line 66 in src/scripts/testing.ts

View workflow job for this annotation

GitHub Actions / code-quality

Expected a `for-of` loop instead of a `for` loop with this simple iteration
const testCase = testCases[j];
const testCaseName = testCase["attributes"]["name"];
const testCaseFailure = testCase["elements"][0].filter(
(element: any) => element.name === "failure",
);
if (testCaseFailure) {
const file = testCase["attributes"]["file"];
const line = testCase["attributes"]["line"];
const failureType = testCaseFailure["attributes"]["type"];
const message = testCaseFailure["attributes"]["message"];
outputStr += `<tr><td>${file}</td><td>${testCaseName}</td><td>${line}</td><td>${failureType}</td><td>${message}</td></tr>`;
}
}
}

// outputStr += "</table>";
outputStr += "</table>";
}
return await buildComment(response, outputStr, command.label);

Expand Down

0 comments on commit c6e0295

Please sign in to comment.