test: add clean-pip tests

This commit is contained in:
Simon BRICHE 2025-11-18 15:42:42 +01:00
parent 24d38ec410
commit 8d89100a02

View 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.');
});
});