Skip to content

Commit 0f72e88

Browse files
committed
update view generation preferences
1 parent 07ac304 commit 0f72e88

File tree

2 files changed

+53
-56
lines changed

2 files changed

+53
-56
lines changed

src/testResultsSummary.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,26 @@ export function getTestResults(
200200
runnerTemp: string,
201201
runId: string,
202202
workspace: string,
203-
): TestResultsData {
204-
const testResults: MatlabTestFile[][] = [];
205-
const stats: TestStatistics = {
206-
Total: 0,
207-
Passed: 0,
208-
Failed: 0,
209-
Incomplete: 0,
210-
NotRun: 0,
211-
Duration: 0,
212-
};
213-
const testResultsData: TestResultsData = {
214-
TestResults: testResults,
215-
Stats: stats,
216-
};
203+
): TestResultsData | null {
204+
let testResultsData = null;
217205
const resultsPath = path.join(runnerTemp, `matlabTestResults${runId}.json`);
218206

219207
if (existsSync(resultsPath)) {
220208
try {
221209
const testArtifact = JSON.parse(readFileSync(resultsPath, "utf8"));
210+
const testResults: MatlabTestFile[][] = [];
211+
const stats: TestStatistics = {
212+
Total: 0,
213+
Passed: 0,
214+
Failed: 0,
215+
Incomplete: 0,
216+
NotRun: 0,
217+
Duration: 0,
218+
};
219+
testResultsData = {
220+
TestResults: testResults,
221+
Stats: stats,
222+
};
222223

223224
for (const jsonTestSessionResults of testArtifact) {
224225
const testSessionResults: MatlabTestFile[] = [];

src/testResultsSummary.unit.test.ts

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jest.mock("fs", () => ({
2121

2222
describe("Artifact Processing Tests", () => {
2323
// Shared test data
24-
let testResultsData: testResultsSummary.TestResultsData;
24+
let testResultsData: testResultsSummary.TestResultsData | null;
2525
let testResults: testResultsSummary.MatlabTestFile[][];
2626
let stats: testResultsSummary.TestStatistics;
2727

@@ -35,8 +35,10 @@ describe("Artifact Processing Tests", () => {
3535
copyTestDataFile(osInfo.osName, runnerTemp, runId, actionName);
3636

3737
testResultsData = testResultsSummary.getTestResults(runnerTemp, runId, workspace);
38-
testResults = testResultsData.TestResults;
39-
stats = testResultsData.Stats;
38+
if (testResultsData) {
39+
testResults = testResultsData.TestResults;
40+
stats = testResultsData.Stats;
41+
}
4042
});
4143

4244
function getOSInfo() {
@@ -137,32 +139,34 @@ describe("Artifact Processing Tests", () => {
137139
});
138140

139141
it("should write test results data to the GitHub job summary", () => {
140-
const actionName = process.env.GITHUB_ACTION || "";
141-
testResultsSummary.writeSummary(testResultsData, actionName);
142-
143-
expect(core.summary.addHeading).toHaveBeenCalledTimes(2);
144-
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
145-
1,
146-
expect.stringContaining("MATLAB Test Results (" + actionName + ")"),
147-
);
148-
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
149-
1,
150-
expect.stringContaining(
151-
'<a href="https://github.com/matlab-actions/run-tests/blob/main/README.md#view-test-results"',
152-
),
153-
);
154-
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
155-
1,
156-
expect.stringContaining('target="_blank"'),
157-
);
158-
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
159-
1,
160-
expect.stringContaining("ℹ️</a>"),
161-
);
162-
expect(core.summary.addHeading).toHaveBeenNthCalledWith(2, "All tests", 3);
142+
if (testResultsData) {
143+
const actionName = process.env.GITHUB_ACTION || "";
144+
testResultsSummary.writeSummary(testResultsData, actionName);
145+
146+
expect(core.summary.addHeading).toHaveBeenCalledTimes(2);
147+
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
148+
1,
149+
expect.stringContaining("MATLAB Test Results (" + actionName + ")"),
150+
);
151+
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
152+
1,
153+
expect.stringContaining(
154+
'<a href="https://github.com/matlab-actions/run-tests/blob/main/README.md#view-test-results"',
155+
),
156+
);
157+
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
158+
1,
159+
expect.stringContaining('target="_blank"'),
160+
);
161+
expect(core.summary.addHeading).toHaveBeenNthCalledWith(
162+
1,
163+
expect.stringContaining("ℹ️</a>"),
164+
);
165+
expect(core.summary.addHeading).toHaveBeenNthCalledWith(2, "All tests", 3);
163166

164-
expect(core.summary.addRaw).toHaveBeenCalledTimes(2);
165-
expect(core.summary.write).toHaveBeenCalledTimes(1);
167+
expect(core.summary.addRaw).toHaveBeenCalledTimes(2);
168+
expect(core.summary.write).toHaveBeenCalledTimes(1);
169+
}
166170
});
167171
});
168172

@@ -368,17 +372,7 @@ describe("Error Handling Tests", () => {
368372

369373
try {
370374
const result = testResultsSummary.getTestResults(process.env.RUNNER_TEMP, process.env.GITHUB_RUN_ID, "");
371-
372-
// Should return empty results
373-
expect(result.TestResults).toEqual([]);
374-
expect(result.Stats).toEqual({
375-
Total: 0,
376-
Passed: 0,
377-
Failed: 0,
378-
Incomplete: 0,
379-
NotRun: 0,
380-
Duration: 0,
381-
});
375+
expect(result).toBeNull();
382376

383377
// Verify error was logged
384378
expect(consoleSpy).toHaveBeenCalledWith(
@@ -419,9 +413,11 @@ describe("Error Handling Tests", () => {
419413
try {
420414
const result = testResultsSummary.getTestResults(process.env.RUNNER_TEMP, process.env.GITHUB_RUN_ID, "");
421415

422-
// Should still return results even if deletion fails
423-
expect(result).toBeDefined();
424-
expect(result.TestResults).toEqual([]);
416+
if(result){
417+
// Should still return results even if deletion fails
418+
expect(result).toBeDefined();
419+
expect(result.TestResults).toEqual([]);
420+
}
425421

426422
// Verify deletion error was logged
427423
expect(consoleSpy).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)