|
6 | 6 | * variables following the pattern `INPUT_<INPUT_NAME>`. |
7 | 7 | */ |
8 | 8 |
|
9 | | -import * as core from '@actions/core' |
| 9 | +//import * as core from '@actions/core' |
10 | 10 | import * as main from '../src/main' |
| 11 | +import fetchMock from 'jest-fetch-mock' |
11 | 12 |
|
12 | 13 | // Mock the action's main function |
13 | 14 | const runMock = jest.spyOn(main, 'run') |
14 | 15 |
|
15 | | -// Other utilities |
16 | | -const timeRegex = /^\d{2}:\d{2}:\d{2}/ |
17 | | - |
18 | 16 | // 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> |
| 17 | +// let debugMock: jest.SpiedFunction<typeof core.debug> |
| 18 | +// let errorMock: jest.SpiedFunction<typeof core.error> |
| 19 | +// let getInputMock: jest.SpiedFunction<typeof core.getInput> |
| 20 | +// let setFailedMock: jest.SpiedFunction<typeof core.setFailed> |
| 21 | +//let setOutputMock: jest.SpiedFunction<typeof core.setOutput> |
| 22 | + |
| 23 | +fetchMock.enableMocks() |
24 | 24 |
|
25 | 25 | describe('action', () => { |
26 | 26 | beforeEach(() => { |
27 | 27 | jest.clearAllMocks() |
| 28 | + fetchMock.resetMocks() |
28 | 29 |
|
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() |
| 30 | + // debugMock = jest.spyOn(core, 'debug').mockImplementation() |
| 31 | + // errorMock = jest.spyOn(core, 'error').mockImplementation() |
| 32 | + // getInputMock = jest.spyOn(core, 'getInput').mockImplementation() |
| 33 | + // setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() |
| 34 | + //setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() |
66 | 35 | }) |
67 | 36 |
|
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 | | - |
| 37 | + it('should run', async () => { |
79 | 38 | await main.run() |
80 | 39 | 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 | 40 | }) |
89 | 41 | }) |
0 commit comments