Skip to content

Commit

Permalink
fix: skip writing snap file, if content didn't change (#1456)
Browse files Browse the repository at this point in the history
* fix: skip writing snap file, if content didn't change

* chore: cleanup
  • Loading branch information
sheremet-va committed Jun 10, 2022
1 parent 9a87a3c commit 97106f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/vitest/src/integrations/snapshot/port/utils.ts
Expand Up @@ -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',
)
}
Expand Down

0 comments on commit 97106f6

Please sign in to comment.