Skip to content

Commit

Permalink
chore: unit test avoid writing unnecessarily
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Oct 20, 2023
1 parent 8254fbf commit 3e7a432
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/unit-tests/__tests__/lib/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 3e7a432

Please sign in to comment.