From 97106f6b8f79a8ae26aefc5ec601b5918cdf5777 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Fri, 10 Jun 2022 10:10:02 +0300 Subject: [PATCH] fix: skip writing snap file, if content didn't change (#1456) * fix: skip writing snap file, if content didn't change * chore: cleanup --- packages/vitest/src/integrations/snapshot/port/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/vitest/src/integrations/snapshot/port/utils.ts b/packages/vitest/src/integrations/snapshot/port/utils.ts index f05e0398adbb..a2fc5b2e5a1b 100644 --- a/packages/vitest/src/integrations/snapshot/port/utils.ts +++ b/packages/vitest/src/integrations/snapshot/port/utils.ts @@ -151,10 +151,16 @@ export async function saveSnapshotFile( key => `exports[${printBacktickString(key)}] = ${printBacktickString(normalizeNewlines(snapshotData[key]))};`, ) + const content = `${writeSnapshotVersion()}\n\n${snapshots.join('\n\n')}\n` + const skipWriting = fs.existsSync(snapshotPath) && (await fsp.readFile(snapshotPath, 'utf8')) === content + + if (skipWriting) + return + ensureDirectoryExists(snapshotPath) await fsp.writeFile( snapshotPath, - `${writeSnapshotVersion()}\n\n${snapshots.join('\n\n')}\n`, + content, 'utf-8', ) }