Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbhoski committed May 24, 2024
1 parent 6920726 commit 226b2aa
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions src/buildSummary.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,7 @@ jest.mock('@actions/core', () => ({

const mockReadFile = readFile as jest.MockedFunction<typeof readFile>;

describe('readJsonFile', () => {
it('reads and parses a JSON file successfully', async () => {
const mockData = JSON.stringify({
taskDetails: [
{ name: 'Test Task', description: 'A test task', failed: false, skipped: false, duration: '00:00:10' },
],
});
mockReadFile.mockImplementation((path, options, callback) => void) => {
callback(null, mockData);
});

const filePath = 'path/to/mockFile.json';
const data = await buildSummary.readJsonFile(filePath as string);

expect(data).toEqual(JSON.parse(mockData));
expect(mockReadFile).toHaveBeenCalledWith(filePath, { encoding: 'utf8' }, expect.any(Function));
});

it('throws an error if the file cannot be read', async () => {
mockReadFile.mockImplementation((path, options, callback) => void) => {
callback(new Error('File not found'), null);
});

const filePath = 'path/to/nonExistentFile.json';
await expect(buildSummary.readJsonFile(filePath as string)).rejects.toThrow('File not found');
});

describe('summaryGeneration', () => {
it('generates a summary table correctly', () => {
const mockTasks = {
taskDetails: [
Expand Down

0 comments on commit 226b2aa

Please sign in to comment.