From dcb33004e12a809d8f9cda215deb10dcb7f3df27 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 24 Apr 2020 23:40:53 +0200
Subject: [PATCH] fix: writeLocalFile during autoReplace

---
 lib/workers/branch/auto-replace.spec.ts | 2 ++
 lib/workers/branch/auto-replace.ts      | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/lib/workers/branch/auto-replace.spec.ts b/lib/workers/branch/auto-replace.spec.ts
index 4a1387972d..09623bfa58 100644
--- a/lib/workers/branch/auto-replace.spec.ts
+++ b/lib/workers/branch/auto-replace.spec.ts
@@ -10,6 +10,8 @@ const sampleHtml = readFileSync(
   'utf8'
 );
 
+jest.mock('../../util/fs');
+
 describe('workers/branch/auto-replace', () => {
   describe('doAutoReplace', () => {
     let parentBranch;
diff --git a/lib/workers/branch/auto-replace.ts b/lib/workers/branch/auto-replace.ts
index 6b5afb6840..d31c854149 100644
--- a/lib/workers/branch/auto-replace.ts
+++ b/lib/workers/branch/auto-replace.ts
@@ -4,6 +4,7 @@ import { WORKER_FILE_UPDATE_FAILED } from '../../constants/error-messages';
 import { matchAt, replaceAt } from '../../util/string';
 import { regEx, escapeRegExp } from '../../util/regex';
 import { compile } from '../../util/template';
+import { writeLocalFile } from '../../util/fs';
 
 export async function confirmIfDepUpdated(
   upgrade,
@@ -122,9 +123,12 @@ export async function doAutoReplace(
           replaceString,
           newString
         );
+        await writeLocalFile(upgrade.packageFile, testContent);
         if (await confirmIfDepUpdated(upgrade, testContent)) {
           return testContent;
         }
+        // istanbul ignore next
+        await writeLocalFile(upgrade.packageFile, existingContent);
       }
     }
   } catch (err) /* istanbul ignore next */ {
-- 
GitLab