mirror of
https://github.com/actions/setup-python.git
synced 2025-12-09 06:05:19 +00:00
test: add clean-pip tests
This commit is contained in:
parent
24d38ec410
commit
8d89100a02
42
__tests__/clean-pip.test.ts
Normal file
42
__tests__/clean-pip.test.ts
Normal file
@ -0,0 +1,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.');
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user