From 908323d13a93b3a85ff3ddcf9b7408a2274b838a Mon Sep 17 00:00:00 2001 From: Chapman Pendery Date: Wed, 6 Mar 2024 22:35:55 -0800 Subject: [PATCH] fix: snapshot locking fails when snapshot first is getting created 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