Skip to content

Commit

Permalink
fix: snapshot locking fails when snapshot first is getting created (#19)
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Mar 7, 2024
1 parent 1e740bf commit daf7c68
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/test/matchers/toMatchSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ const updateSnapshot = async (
snapshot: string
): Promise<void> => {
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,
Expand Down Expand Up @@ -180,6 +183,7 @@ export async function toMatchSnapshot(
} else {
emitResult();
}

return {
pass: !snapshotsDifferent,
message: !snapshotsDifferent
Expand Down

0 comments on commit daf7c68

Please sign in to comment.