From 8d89100a024fbf80cc043ba31b70f2096d797c6f Mon Sep 17 00:00:00 2001 From: Simon BRICHE Date: Tue, 18 Nov 2025 15:42:42 +0100 Subject: [PATCH] test: add clean-pip tests --- __tests__/clean-pip.test.ts | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 __tests__/clean-pip.test.ts diff --git a/__tests__/clean-pip.test.ts b/__tests__/clean-pip.test.ts new file mode 100644 index 00000000..ff35fcaf --- /dev/null +++ b/__tests__/clean-pip.test.ts @@ -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.'); + }); +});