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