forked from linear-b/gitstream-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-python.test.ts
More file actions
44 lines (35 loc) · 1.26 KB
/
Copy pathsetup-python.test.ts
File metadata and controls
44 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as core from '@actions/core'
import { execSync } from 'child_process'
import { installBlack } from '../src/support-python'
jest.mock('@actions/core')
jest.mock('child_process')
describe('installBlack', () => {
const debugMock = jest.spyOn(core, 'debug')
const warningMock = jest.spyOn(core, 'warning')
const execSyncMock = execSync as jest.MockedFunction<typeof execSync>
beforeEach(() => {
jest.clearAllMocks()
})
it('should install black successfully', async () => {
execSyncMock.mockReturnValue('Successfully installed black')
await installBlack()
expect(debugMock).toHaveBeenCalledWith(
'run command: "pip install black==24.4.2"'
)
expect(debugMock).toHaveBeenCalledWith('Successfully installed black')
expect(warningMock).not.toHaveBeenCalled()
})
it('should handle errors correctly', async () => {
execSyncMock.mockImplementation(() => {
throw new Error('Failed to install black')
})
await installBlack()
expect(debugMock).toHaveBeenCalledWith(
'run command: "pip install black==24.4.2"'
)
expect(warningMock).toHaveBeenCalledWith(
'Failed to install black with command pip install black==24.4.2'
)
expect(warningMock).toHaveBeenCalledWith(expect.any(Error))
})
})