From bb9c10e250bcd22860b4ad1c6692e57ea561073f Mon Sep 17 00:00:00 2001
From: Oleg Krivtsov <olegkrivtsov@gmail.com>
Date: Fri, 18 Feb 2022 12:45:25 +0700
Subject: [PATCH] chore(pip_requirements): migrate from fs.readFile to
 fs.readLocalFile (#14232)

---
 .../pip_requirements/artifacts.spec.ts        | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/manager/pip_requirements/artifacts.spec.ts b/lib/manager/pip_requirements/artifacts.spec.ts
index 61af191fa3..1d12840145 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,
-- 
GitLab