Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed Aug 13, 2024
1 parent 548cba9 commit e905eca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/buildSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export function processAndDisplayBuildSummary() {
const header = [{ data: 'MATLAB Build Task', header: true }, { data: 'Status', header: true }, { data: 'Description', header: true }, { data: 'Duration (hh:mm:ss)', header: true }];

const filePath: string = join(runnerTemp, `buildSummary${runId}.json`);
let taskSummaryTableRows;
let taskSummaryTable;
if (existsSync(filePath)) {
try {
const buildSummary = readFileSync(filePath, { encoding: 'utf8' });
const rows = getSummaryRows(buildSummary);
taskSummaryTableRows = [header, ...rows];
taskSummaryTable = [header, ...rows];
} catch (e) {
console.error('An error occurred while reading the build summary file:', e);
return;
Expand All @@ -56,7 +56,7 @@ export function processAndDisplayBuildSummary() {
console.error(`An error occurred while trying to delete the build summary file ${filePath}:`, e);
}
}
writeSummary(taskSummaryTableRows);
writeSummary(taskSummaryTable);
} else {
core.info(`Build summary data not created.`);
}
Expand Down
16 changes: 16 additions & 0 deletions src/buildSummary.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ jest.mock('@actions/core', () => ({
}));

describe('summaryGeneration', () => {
it('should process and return summary rows for valid JSON with different task statuses', () => {
const mockBuildSummary = JSON.stringify([
{ name: 'Task 1', failed: true, skipped: false, description: 'Task 1 description', duration: '00:00:10' },
{ name: 'Task 2', failed: false, skipped: true, description: 'Task 2 description', duration: '00:00:20' },
{ name: 'Task 3', failed: false, skipped: false, description: 'Task 3 description', duration: '00:00:30' }
]);

const result = buildSummary.getSummaryRows(mockBuildSummary);

expect(result).toEqual([
['Task 1', '🔴 Failed', 'Task 1 description', '00:00:10'],
['Task 2', '🔵 Skipped', 'Task 2 description', '00:00:20'],
['Task 3', '🟢 Success', 'Task 3 description', '00:00:30']
]);
});

it('writes the summary correctly', () => {
const mockTableRows = [
['MATLAB Build Task', 'Status', 'Description', 'Duration (hh:mm:ss)'],
Expand Down

0 comments on commit e905eca

Please sign in to comment.