|
8 | 8 |
|
9 | 9 | import * as core from '@actions/core' |
10 | 10 | import * as main from '../src/main' |
| 11 | +import * as fs from 'fs' |
| 12 | +import * as path from 'path' |
| 13 | +import * as os from 'os' |
11 | 14 |
|
12 | 15 | // Mock the action's main function |
13 | 16 | const runMock = jest.spyOn(main, 'run') |
14 | 17 |
|
| 18 | +jest.setTimeout(60 * 1000) |
| 19 | + |
| 20 | +const tmpDir = fs.mkdtempSync( |
| 21 | + path.join(os.tmpdir(), 'qt-creator-downloader-test') |
| 22 | +) |
| 23 | + |
15 | 24 | // Other utilities |
16 | | -const timeRegex = /^\d{2}:\d{2}:\d{2}/ |
17 | 25 |
|
18 | 26 | // Mock the GitHub Actions core library |
19 | | -let debugMock: jest.SpiedFunction<typeof core.debug> |
20 | 27 | let errorMock: jest.SpiedFunction<typeof core.error> |
21 | 28 | let getInputMock: jest.SpiedFunction<typeof core.getInput> |
22 | | -let setFailedMock: jest.SpiedFunction<typeof core.setFailed> |
23 | | -let setOutputMock: jest.SpiedFunction<typeof core.setOutput> |
24 | 29 |
|
25 | 30 | describe('action', () => { |
26 | 31 | beforeEach(() => { |
27 | 32 | jest.clearAllMocks() |
28 | 33 |
|
29 | | - debugMock = jest.spyOn(core, 'debug').mockImplementation() |
30 | 34 | errorMock = jest.spyOn(core, 'error').mockImplementation() |
31 | 35 | getInputMock = jest.spyOn(core, 'getInput').mockImplementation() |
32 | | - setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() |
33 | | - setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() |
34 | 36 | }) |
35 | 37 |
|
36 | | - it('sets the time output', async () => { |
| 38 | + it('downloads 14.0.0', async () => { |
37 | 39 | // Set the action's inputs as return values from core.getInput() |
38 | 40 | getInputMock.mockImplementation(name => { |
39 | 41 | switch (name) { |
40 | | - case 'milliseconds': |
41 | | - return '500' |
| 42 | + case 'version': |
| 43 | + return '14.0.0' |
| 44 | + case 'unzip-to': |
| 45 | + return tmpDir |
42 | 46 | default: |
43 | 47 | return '' |
44 | 48 | } |
45 | 49 | }) |
46 | 50 |
|
47 | 51 | await main.run() |
48 | 52 | 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 | 53 | expect(errorMock).not.toHaveBeenCalled() |
88 | 54 | }) |
89 | 55 | }) |
0 commit comments