From 3e7a432ed0884881aa3cf2d98b66fcb52678436d Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Fri, 20 Oct 2023 08:48:46 +0200 Subject: [PATCH] chore: unit test avoid writing unnecessarily --- lib/unit-tests/__tests__/lib/validator.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/unit-tests/__tests__/lib/validator.ts b/lib/unit-tests/__tests__/lib/validator.ts index 28d846c..97003af 100644 --- a/lib/unit-tests/__tests__/lib/validator.ts +++ b/lib/unit-tests/__tests__/lib/validator.ts @@ -35,7 +35,14 @@ export async function setupValidator(): Promise<{ validate: SchemaValidator; cac if (cache) { // Store cache to disk: - await fs.promises.writeFile(cachePath, JSON.stringify(cache), 'utf-8') + const existingFileContents = await fs.promises.readFile(cachePath, 'utf-8').catch((e) => { + if (e.code === 'ENOENT') return '' + else throw e + }) + const newFileContents = JSON.stringify(cache) + if (newFileContents !== existingFileContents) { + await fs.promises.writeFile(cachePath, newFileContents, 'utf-8') + } } return { validate, cache }