Skip to content

Commit 4b5f31d

Browse files
committed
add filename sorting and remove unnecessary variable
1 parent d7d388a commit 4b5f31d

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/testResultsSummary.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,24 @@ export interface TestResultsData {
6969
}
7070

7171
export function processAndAddTestSummary(runnerTemp: string, runId: string, workspace: string) {
72-
const testResultsData = getTestResults(runnerTemp, runId, workspace);
72+
const testResultsData = getTestResults(runnerTemp, workspace);
7373
const coverageResultsData = getCoverageResults(runnerTemp, runId);
7474
if (testResultsData || coverageResultsData) {
7575
addSummary(testResultsData, coverageResultsData);
7676
}
7777
}
7878

79-
export function getTestResults(
80-
runnerTemp: string,
81-
runId: string,
82-
workspace: string,
83-
): TestResultsData | null {
79+
export function getTestResults(runnerTemp: string, workspace: string): TestResultsData | null {
8480
let testResultsData = null;
8581
const filePrefix = `matlabTestResults_`;
8682
const fileSuffix = `.json`;
8783

8884
// Find all test result files matching the pattern
8985
let testResultFiles: string[] = [];
9086
try {
91-
testResultFiles = readdirSync(runnerTemp).filter(
92-
(file) => file.startsWith(filePrefix) && file.endsWith(fileSuffix),
93-
);
87+
testResultFiles = readdirSync(runnerTemp)
88+
.filter((file) => file.startsWith(filePrefix) && file.endsWith(fileSuffix))
89+
.sort();
9490
} catch (e) {
9591
console.error(
9692
`An error occurred while finding test results summary file(s) in directory ${runnerTemp}:`,

src/testResultsSummary.unit.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ describe("Artifact Processing Tests", () => {
4646

4747
beforeAll(() => {
4848
const runnerTemp = path.join(import.meta.dirname, "..");
49-
const runId = "123";
5049
const osInfo = getOSInfo();
5150
const workspace = path.join(osInfo.workspaceParent, "workspace");
5251

5352
copyTestDataFile(osInfo.osName, runnerTemp);
5453

55-
testResultsData = testResultsSummary.getTestResults(runnerTemp, runId, workspace);
54+
testResultsData = testResultsSummary.getTestResults(runnerTemp, workspace);
5655
if (testResultsData) {
5756
testSession = testResultsData.TestSessions[0];
5857
testResults = testSession.TestResults;
@@ -403,7 +402,6 @@ describe("Multiple Sessions Tests", () => {
403402

404403
beforeAll(() => {
405404
const runnerTemp = path.join(import.meta.dirname, "..");
406-
const runId = "456";
407405
const osInfo = getOSInfo();
408406
const workspace = path.join(osInfo.workspaceParent, "workspace");
409407

@@ -427,7 +425,7 @@ describe("Multiple Sessions Tests", () => {
427425
console.error("Error copying test-data:", err);
428426
}
429427

430-
testResultsData = testResultsSummary.getTestResults(runnerTemp, runId, workspace);
428+
testResultsData = testResultsSummary.getTestResults(runnerTemp, workspace);
431429

432430
// Clean up test files since unlinkSync is mocked
433431
try {
@@ -536,13 +534,13 @@ describe("Multiple Sessions Tests", () => {
536534
describe("No Results Tests", () => {
537535
it("should return null when no matching files exist", () => {
538536
const emptyDir = path.join(import.meta.dirname, "test-data");
539-
const result = testResultsSummary.getTestResults(emptyDir, "999", "");
537+
const result = testResultsSummary.getTestResults(emptyDir, "");
540538
expect(result).toBeNull();
541539
});
542540

543541
it("should return null when directory does not exist", () => {
544542
const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {});
545-
const result = testResultsSummary.getTestResults("/nonexistent/directory/path", "999", "");
543+
const result = testResultsSummary.getTestResults("/nonexistent/directory/path", "");
546544
expect(result).toBeNull();
547545
expect(consoleSpy).toHaveBeenCalled();
548546
expect(consoleSpy.mock.calls[0][0] as string).toContain(
@@ -604,7 +602,7 @@ describe("Error Handling Tests", () => {
604602
fs.writeFileSync(invalidJsonPath, "{ invalid json content");
605603

606604
try {
607-
const result = testResultsSummary.getTestResults(runnerTemp, "123", "");
605+
const result = testResultsSummary.getTestResults(runnerTemp, "");
608606
expect(result).not.toBeNull();
609607
expect(result!.TestSessions.length).toBe(0);
610608
expect(result!.OverallStats.Total).toBe(0);
@@ -640,7 +638,7 @@ describe("Error Handling Tests", () => {
640638
fs.writeFileSync(validJsonPath, "[]"); // Empty array - valid JSON
641639

642640
try {
643-
const result = testResultsSummary.getTestResults(runnerTemp, "123", "");
641+
const result = testResultsSummary.getTestResults(runnerTemp, "");
644642

645643
// Should still return results even if deletion fails
646644
expect(result).not.toBeNull();
@@ -707,7 +705,7 @@ describe("Data Processing Edge Cases", () => {
707705
const destPath = path.join(runnerTemp, destFileName);
708706
fs.copyFileSync(sourceFilePath, destPath);
709707

710-
const result = testResultsSummary.getTestResults(runnerTemp, "700", workspace);
708+
const result = testResultsSummary.getTestResults(runnerTemp, workspace);
711709

712710
// Clean up since unlinkSync is mocked
713711
try {

0 commit comments

Comments
 (0)