|
| 1 | +/** |
| 2 | + * Unit tests for the action's main functionality, src/main.ts |
| 3 | + * |
| 4 | + * These should be run as if the action was called from a workflow. |
| 5 | + * Specifically, the inputs listed in `action.yml` should be set as environment |
| 6 | + * variables following the pattern `INPUT_<INPUT_NAME>`. |
| 7 | + */ |
| 8 | + |
| 9 | +// import * as core from '@actions/core' |
| 10 | +// import * as main from '../src/main' |
| 11 | + |
| 12 | +// // Mock the action's main function |
| 13 | +// const runMock = jest.spyOn(main, 'run') |
| 14 | + |
| 15 | +// // Other utilities |
| 16 | +// const timeRegex = /^\d{2}:\d{2}:\d{2}/ |
| 17 | + |
| 18 | +// // Mock the GitHub Actions core library |
| 19 | +// let debugMock: jest.SpiedFunction<typeof core.debug> |
| 20 | +// let errorMock: jest.SpiedFunction<typeof core.error> |
| 21 | +// let getInputMock: jest.SpiedFunction<typeof core.getInput> |
| 22 | +// let setFailedMock: jest.SpiedFunction<typeof core.setFailed> |
| 23 | +// let setOutputMock: jest.SpiedFunction<typeof core.setOutput> |
| 24 | + |
| 25 | +// describe('action', () => { |
| 26 | +// beforeEach(() => { |
| 27 | +// jest.clearAllMocks() |
| 28 | + |
| 29 | +// debugMock = jest.spyOn(core, 'debug').mockImplementation() |
| 30 | +// errorMock = jest.spyOn(core, 'error').mockImplementation() |
| 31 | +// getInputMock = jest.spyOn(core, 'getInput').mockImplementation() |
| 32 | +// setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() |
| 33 | +// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() |
| 34 | +// }) |
| 35 | + |
| 36 | +// it('sets the time output', async () => { |
| 37 | +// // Set the action's inputs as return values from core.getInput() |
| 38 | +// getInputMock.mockImplementation(name => { |
| 39 | +// switch (name) { |
| 40 | +// case 'milliseconds': |
| 41 | +// return '500' |
| 42 | +// default: |
| 43 | +// return '' |
| 44 | +// } |
| 45 | +// }) |
| 46 | + |
| 47 | +// await main.run() |
| 48 | +// expect(runMock).toHaveReturned() |
| 49 | + |
| 50 | +// // Verify that all of the core library functions were called correctly |
| 51 | +// expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') |
| 52 | +// expect(debugMock).toHaveBeenNthCalledWith( |
| 53 | +// 2, |
| 54 | +// expect.stringMatching(timeRegex) |
| 55 | +// ) |
| 56 | +// expect(debugMock).toHaveBeenNthCalledWith( |
| 57 | +// 3, |
| 58 | +// expect.stringMatching(timeRegex) |
| 59 | +// ) |
| 60 | +// expect(setOutputMock).toHaveBeenNthCalledWith( |
| 61 | +// 1, |
| 62 | +// 'time', |
| 63 | +// expect.stringMatching(timeRegex) |
| 64 | +// ) |
| 65 | +// expect(errorMock).not.toHaveBeenCalled() |
| 66 | +// }) |
| 67 | + |
| 68 | +// it('sets a failed status', async () => { |
| 69 | +// // Set the action's inputs as return values from core.getInput() |
| 70 | +// getInputMock.mockImplementation(name => { |
| 71 | +// switch (name) { |
| 72 | +// case 'milliseconds': |
| 73 | +// return 'this is not a number' |
| 74 | +// default: |
| 75 | +// return '' |
| 76 | +// } |
| 77 | +// }) |
| 78 | + |
| 79 | +// await main.run() |
| 80 | +// expect(runMock).toHaveReturned() |
| 81 | + |
| 82 | +// // Verify that all of the core library functions were called correctly |
| 83 | +// expect(setFailedMock).toHaveBeenNthCalledWith( |
| 84 | +// 1, |
| 85 | +// 'milliseconds not a number' |
| 86 | +// ) |
| 87 | +// expect(errorMock).not.toHaveBeenCalled() |
| 88 | +// }) |
| 89 | +// }) |
0 commit comments