Skip to content

Commit d549eb6

Browse files
authored
fixes
1 parent f35baeb commit d549eb6

File tree

14 files changed

+44389
-21678
lines changed

14 files changed

+44389
-21678
lines changed

__tests__/index.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
*/
44

55
import * as main from '../src/main'
6+
import { describe, it, expect, vi } from 'vitest'
67

78
// Mock the action's entrypoint
8-
const runMock = jest.spyOn(main, 'run').mockImplementation()
9+
const runMock = vi.spyOn(main, 'run').mockImplementation()
910

1011
describe('index', () => {
11-
it('calls run when imported', () => {
12-
// eslint-disable-next-line @typescript-eslint/no-require-imports
13-
require('../src/index')
14-
12+
it('calls run when imported', async () => {
13+
await import('../src/index')
1514
expect(runMock).toHaveBeenCalled()
1615
})
1716
})

__tests__/main.test.ts

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,43 @@
88

99
import * as core from '@actions/core'
1010
import * as main from '../src/main'
11+
import { describe, it, beforeEach, expect, vi } from 'vitest'
1112

1213
// Mock the action's main function
13-
const runMock = jest.spyOn(main, 'run')
14+
const runMock = vi.spyOn(main, 'run')
1415

1516
// Other utilities
1617
const timeRegex = /^\d{2}:\d{2}:\d{2}/
1718

1819
// 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>
20+
let debugMock: ReturnType<typeof vi.spyOn>
21+
let errorMock: ReturnType<typeof vi.spyOn>
22+
let getInputMock: ReturnType<typeof vi.spyOn>
23+
let setFailedMock: ReturnType<typeof vi.spyOn>
24+
let setOutputMock: ReturnType<typeof vi.spyOn>
2425

2526
describe('action', () => {
2627
beforeEach(() => {
27-
jest.clearAllMocks()
28+
vi.clearAllMocks()
2829

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()
30+
debugMock = vi.spyOn(core, 'debug').mockImplementation()
31+
errorMock = vi.spyOn(core, 'error').mockImplementation()
32+
getInputMock = vi.spyOn(core, 'getInput').mockImplementation()
33+
setFailedMock = vi.spyOn(core, 'setFailed').mockImplementation()
34+
setOutputMock = vi.spyOn(core, 'setOutput').mockImplementation()
3435
})
3536

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-
})
6737

68-
it('sets a failed status', async () => {
38+
it('sets a failed status for unsupported platform', async () => {
6939
// Set the action's inputs as return values from core.getInput()
7040
getInputMock.mockImplementation(name => {
7141
switch (name) {
72-
case 'milliseconds':
73-
return 'this is not a number'
42+
case 'action':
43+
return 'test-action'
44+
case 'project':
45+
return 'test-project'
46+
case 'pipelab-version':
47+
return '1.0.0'
7448
default:
7549
return ''
7650
}
@@ -79,11 +53,8 @@ describe('action', () => {
7953
await main.run()
8054
expect(runMock).toHaveReturned()
8155

82-
// Verify that all of the core library functions were called correctly
83-
expect(setFailedMock).toHaveBeenNthCalledWith(
84-
1,
85-
'milliseconds not a number'
86-
)
56+
// Verify that the core.setFailed function was called correctly
57+
expect(setFailedMock).toHaveBeenCalledWith('You are using an unsupported platform')
8758
expect(errorMock).not.toHaveBeenCalled()
8859
})
8960
})

__tests__/wait.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)