|
6 | 6 | * variables following the pattern `INPUT_<INPUT_NAME>`. |
7 | 7 | */ |
8 | 8 |
|
9 | | -import * as core from '@actions/core' |
10 | | -import * as main from '../src/main' |
| 9 | +import * as core from '@actions/core'; |
| 10 | +import * as main from '../src/main'; |
11 | 11 |
|
12 | 12 | // Mock the action's main function |
13 | | -const runMock = jest.spyOn(main, 'run') |
| 13 | +const runMock = jest.spyOn(main, 'run'); |
14 | 14 |
|
15 | 15 | // Other utilities |
16 | | -const timeRegex = /^\d{2}:\d{2}:\d{2}/ |
| 16 | +const timeRegex = /^\d{2}:\d{2}:\d{2}/; |
17 | 17 |
|
18 | 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> |
| 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 | 24 |
|
25 | 25 | describe('action', () => { |
26 | 26 | beforeEach(() => { |
27 | | - jest.clearAllMocks() |
| 27 | + jest.clearAllMocks(); |
28 | 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 | | - }) |
| 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 | 35 |
|
36 | 36 | it('sets the time output', async () => { |
37 | 37 | // Set the action's inputs as return values from core.getInput() |
38 | 38 | getInputMock.mockImplementation(name => { |
39 | 39 | switch (name) { |
40 | 40 | case 'milliseconds': |
41 | | - return '500' |
| 41 | + return '500'; |
42 | 42 | default: |
43 | | - return '' |
| 43 | + return ''; |
44 | 44 | } |
45 | | - }) |
| 45 | + }); |
46 | 46 |
|
47 | | - await main.run() |
48 | | - expect(runMock).toHaveReturned() |
| 47 | + await main.run(); |
| 48 | + expect(runMock).toHaveReturned(); |
49 | 49 |
|
50 | 50 | // Verify that all of the core library functions were called correctly |
51 | | - expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...') |
| 51 | + expect(debugMock).toHaveBeenNthCalledWith( |
| 52 | + 1, |
| 53 | + 'Waiting 500 milliseconds ...' |
| 54 | + ); |
52 | 55 | expect(debugMock).toHaveBeenNthCalledWith( |
53 | 56 | 2, |
54 | 57 | expect.stringMatching(timeRegex) |
55 | | - ) |
| 58 | + ); |
56 | 59 | expect(debugMock).toHaveBeenNthCalledWith( |
57 | 60 | 3, |
58 | 61 | expect.stringMatching(timeRegex) |
59 | | - ) |
| 62 | + ); |
60 | 63 | expect(setOutputMock).toHaveBeenNthCalledWith( |
61 | 64 | 1, |
62 | 65 | 'time', |
63 | 66 | expect.stringMatching(timeRegex) |
64 | | - ) |
65 | | - expect(errorMock).not.toHaveBeenCalled() |
66 | | - }) |
| 67 | + ); |
| 68 | + expect(errorMock).not.toHaveBeenCalled(); |
| 69 | + }); |
67 | 70 |
|
68 | 71 | it('sets a failed status', async () => { |
69 | 72 | // Set the action's inputs as return values from core.getInput() |
70 | 73 | getInputMock.mockImplementation(name => { |
71 | 74 | switch (name) { |
72 | 75 | case 'milliseconds': |
73 | | - return 'this is not a number' |
| 76 | + return 'this is not a number'; |
74 | 77 | default: |
75 | | - return '' |
| 78 | + return ''; |
76 | 79 | } |
77 | | - }) |
| 80 | + }); |
78 | 81 |
|
79 | | - await main.run() |
80 | | - expect(runMock).toHaveReturned() |
| 82 | + await main.run(); |
| 83 | + expect(runMock).toHaveReturned(); |
81 | 84 |
|
82 | 85 | // Verify that all of the core library functions were called correctly |
83 | 86 | expect(setFailedMock).toHaveBeenNthCalledWith( |
84 | 87 | 1, |
85 | 88 | 'milliseconds not a number' |
86 | | - ) |
87 | | - expect(errorMock).not.toHaveBeenCalled() |
88 | | - }) |
89 | | -}) |
| 89 | + ); |
| 90 | + expect(errorMock).not.toHaveBeenCalled(); |
| 91 | + }); |
| 92 | +}); |
0 commit comments