diff --git a/lib/manager/pip_requirements/artifacts.spec.ts b/lib/manager/pip_requirements/artifacts.spec.ts index 61af191fa3b3ab07609665ae04e613bb2e557e38..1d1284014513a992df5a8930d8b3c8dc81722df4 100644 --- a/lib/manager/pip_requirements/artifacts.spec.ts +++ b/lib/manager/pip_requirements/artifacts.spec.ts @@ -1,13 +1,11 @@ -import _fs from 'fs-extra'; +import { fs } from '../../../test/util'; import { GlobalConfig } from '../../config/global'; import type { UpdateArtifactsConfig } from '../types'; import { updateArtifacts } from './artifacts'; -const fs: jest.Mocked<typeof _fs> = _fs as any; - -jest.mock('fs-extra'); jest.mock('child_process'); jest.mock('../../util/exec'); +jest.mock('../../util/fs'); const config: UpdateArtifactsConfig = {}; @@ -21,6 +19,7 @@ describe('manager/pip_requirements/artifacts', () => { jest.resetModules(); GlobalConfig.set({ localDir: '' }); }); + it('returns null if no updatedDeps were provided', async () => { expect( await updateArtifacts({ @@ -31,8 +30,9 @@ describe('manager/pip_requirements/artifacts', () => { }) ).toBeNull(); }); + it('returns null if no hashes', async () => { - fs.readFile.mockResolvedValueOnce('eventlet==0.30.2\npbr>=1.9\n' as any); + fs.readLocalFile.mockResolvedValueOnce('eventlet==0.30.2\npbr>=1.9\n'); expect( await updateArtifacts({ packageFileName: 'requirements.txt', @@ -42,8 +42,9 @@ describe('manager/pip_requirements/artifacts', () => { }) ).toBeNull(); }); + it('returns null if unchanged', async () => { - fs.readFile.mockResolvedValueOnce(newPackageFileContent as any); + fs.readLocalFile.mockResolvedValueOnce(newPackageFileContent); expect( await updateArtifacts({ packageFileName: 'requirements.txt', @@ -53,8 +54,9 @@ describe('manager/pip_requirements/artifacts', () => { }) ).toBeNull(); }); + it('returns updated file', async () => { - fs.readFile.mockResolvedValueOnce('new content' as any); + fs.readLocalFile.mockResolvedValueOnce('new content'); expect( await updateArtifacts({ packageFileName: 'requirements.txt', @@ -64,8 +66,11 @@ describe('manager/pip_requirements/artifacts', () => { }) ).toHaveLength(1); }); + it('catches and returns errors', async () => { - fs.readFile.mockResolvedValueOnce('new content' as any); + fs.readLocalFile.mockImplementation(() => { + throw new Error('some-error'); + }); expect( await updateArtifacts({ packageFileName: null,