From 7bf04993ca1a6708b0e5e500af74e49bb5a20ed2 Mon Sep 17 00:00:00 2001 From: Daniel Eshkeri Date: Fri, 6 Dec 2024 10:23:52 +0000 Subject: [PATCH] removed tests --- __tests__/main.test.ts | 154 ++++++++++++++++++++++------------------- __tests__/wait.test.ts | 25 ------- 2 files changed, 84 insertions(+), 95 deletions(-) delete mode 100644 __tests__/wait.test.ts diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index ce373fb..b7ae004 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -6,84 +6,98 @@ * variables following the pattern `INPUT_`. */ -import * as core from '@actions/core' -import * as main from '../src/main' +// import * as core from '@actions/core' +// import * as main from '../src/main' -// Mock the action's main function -const runMock = jest.spyOn(main, 'run') +// // Mock the action's main function +// const runMock = jest.spyOn(main, 'run') -// Other utilities -const timeRegex = /^\d{2}:\d{2}:\d{2}/ +// // Other utilities +// const timeRegex = /^\d{2}:\d{2}:\d{2}/ -// Mock the GitHub Actions core library -let debugMock: jest.SpiedFunction -let errorMock: jest.SpiedFunction -let getInputMock: jest.SpiedFunction -let setFailedMock: jest.SpiedFunction -let setOutputMock: jest.SpiedFunction +// // Mock the GitHub Actions core library +// let debugMock: jest.SpiedFunction +// let errorMock: jest.SpiedFunction +// let getInputMock: jest.SpiedFunction +// let setFailedMock: jest.SpiedFunction +// let setOutputMock: jest.SpiedFunction -describe('action', () => { - beforeEach(() => { - jest.clearAllMocks() +// describe('action', () => { +// beforeEach(() => { +// jest.clearAllMocks() - debugMock = jest.spyOn(core, 'debug').mockImplementation() - errorMock = jest.spyOn(core, 'error').mockImplementation() - getInputMock = jest.spyOn(core, 'getInput').mockImplementation() - setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() - setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() - }) +// debugMock = jest.spyOn(core, 'debug').mockImplementation() +// errorMock = jest.spyOn(core, 'error').mockImplementation() +// getInputMock = jest.spyOn(core, 'getInput').mockImplementation() +// setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() +// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() +// }) - it('sets the time output', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation(name => { - switch (name) { - case 'milliseconds': - return '500' - default: - return '' - } - }) +// it('sets the time output', async () => { +// // Set the action's inputs as return values from core.getInput() +// getInputMock.mockImplementation(name => { +// switch (name) { +// case 'working-directory': +// return '.' +// case 'run-static-analysis': +// return 'true' +// case 'run-code-formatting': +// return 'true' +// case 'run-tests': +// return 'true' +// case 'run-coverage': +// return 'true' +// case 'create-comment': +// return 'true' +// case 'coverage-pass-score': +// return '80' +// case 'token': +// return '***' +// default: +// return '' +// } +// }) - await main.run() - expect(runMock).toHaveReturned() +// await main.run() +// expect(runMock).toHaveReturned() - // Verify that all of the core library functions were called correctly - expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') - expect(debugMock).toHaveBeenNthCalledWith( - 2, - expect.stringMatching(timeRegex) - ) - expect(debugMock).toHaveBeenNthCalledWith( - 3, - expect.stringMatching(timeRegex) - ) - expect(setOutputMock).toHaveBeenNthCalledWith( - 1, - 'time', - expect.stringMatching(timeRegex) - ) - expect(errorMock).not.toHaveBeenCalled() - }) +// // Verify that all of the core library functions were called correctly +// expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') +// expect(debugMock).toHaveBeenNthCalledWith( +// 2, +// expect.stringMatching(timeRegex) +// ) +// expect(debugMock).toHaveBeenNthCalledWith( +// 3, +// expect.stringMatching(timeRegex) +// ) +// expect(setOutputMock).toHaveBeenNthCalledWith( +// 1, +// 'time', +// expect.stringMatching(timeRegex) +// ) +// expect(errorMock).not.toHaveBeenCalled() +// }) - it('sets a failed status', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation(name => { - switch (name) { - case 'milliseconds': - return 'this is not a number' - default: - return '' - } - }) +// it('sets a failed status', async () => { +// // Set the action's inputs as return values from core.getInput() +// getInputMock.mockImplementation(name => { +// switch (name) { +// case 'milliseconds': +// return 'this is not a number' +// default: +// return '' +// } +// }) - await main.run() - expect(runMock).toHaveReturned() +// await main.run() +// expect(runMock).toHaveReturned() - // Verify that all of the core library functions were called correctly - expect(setFailedMock).toHaveBeenNthCalledWith( - 1, - 'milliseconds not a number' - ) - expect(errorMock).not.toHaveBeenCalled() - }) -}) +// // Verify that all of the core library functions were called correctly +// expect(setFailedMock).toHaveBeenNthCalledWith( +// 1, +// 'milliseconds not a number' +// ) +// expect(errorMock).not.toHaveBeenCalled() +// }) +// }) diff --git a/__tests__/wait.test.ts b/__tests__/wait.test.ts deleted file mode 100644 index 1336aaa..0000000 --- a/__tests__/wait.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Unit tests for src/wait.ts - */ - -import { wait } from '../src/wait' -import { expect } from '@jest/globals' - -describe('wait.ts', () => { - it('throws an invalid number', async () => { - const input = parseInt('foo', 10) - expect(isNaN(input)).toBe(true) - - await expect(wait(input)).rejects.toThrow('milliseconds not a number') - }) - - it('waits with a valid number', async () => { - const start = new Date() - await wait(500) - const end = new Date() - - const delta = Math.abs(end.getTime() - start.getTime()) - - expect(delta).toBeGreaterThan(450) - }) -})