-
Notifications
You must be signed in to change notification settings - Fork 712
Expand file tree
/
Copy pathclean-pip.test.ts
More file actions
42 lines (32 loc) · 1.23 KB
/
clean-pip.test.ts
File metadata and controls
42 lines (32 loc) · 1.23 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
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {cleanPipPackages} from '../src/clean-pip';
describe('cleanPipPackages', () => {
let infoSpy: jest.SpyInstance;
let setFailedSpy: jest.SpyInstance;
let execSpy: jest.SpyInstance;
beforeEach(() => {
infoSpy = jest.spyOn(core, 'info');
infoSpy.mockImplementation(() => undefined);
setFailedSpy = jest.spyOn(core, 'setFailed');
setFailedSpy.mockImplementation(() => undefined);
execSpy = jest.spyOn(exec, 'exec');
execSpy.mockImplementation(() => Promise.resolve(0));
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});
it('should successfully clean up pip packages', async () => {
await cleanPipPackages();
expect(execSpy).toHaveBeenCalledWith('bash', expect.any(Array));
expect(setFailedSpy).not.toHaveBeenCalled();
});
it('should handle errors and set failed status', async () => {
const error = new Error('Exec failed');
execSpy.mockImplementation(() => Promise.reject(error));
await cleanPipPackages();
expect(execSpy).toHaveBeenCalledWith('bash', expect.any(Array));
expect(setFailedSpy).toHaveBeenCalledWith('Failed to clean up pip packages.');
});
});