From daf7c68efcf82305629cc434106ec04414656b4f Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Thu, 7 Mar 2024 01:40:42 -0500 Subject: [PATCH] fix: snapshot locking fails when snapshot first is getting created (#19) Signed-off-by: Chapman Pendery --- src/test/matchers/toMatchSnapshot.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/matchers/toMatchSnapshot.ts b/src/test/matchers/toMatchSnapshot.ts index 09696e8..c798408 100644 --- a/src/test/matchers/toMatchSnapshot.ts +++ b/src/test/matchers/toMatchSnapshot.ts @@ -52,9 +52,12 @@ const updateSnapshot = async ( snapshot: string ): Promise => { const snapPath = snapshotPath(testPath); - if (!fs.existsSync(snapPath)) { + if (!fs.existsSync(path.dirname(snapPath))) { await fsAsync.mkdir(path.dirname(snapPath), { recursive: true }); } + if (!fs.existsSync(snapPath)) { + await fsAsync.appendFile(snapPath, ""); + } const unlock = await lockfile.lock(snapPath, { stale: 5_000, @@ -180,6 +183,7 @@ export async function toMatchSnapshot( } else { emitResult(); } + return { pass: !snapshotsDifferent, message: !snapshotsDifferent