Skip to content

Commit

Permalink
test: when snapshot is missing print how to generate one
Browse files Browse the repository at this point in the history
  • Loading branch information
rluvaton committed Jul 25, 2023
1 parent a0f3ed8 commit 699f9c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
if (process.env.NODE_REGENERATE_SNAPSHOTS) {
await fs.writeFile(snapshot, actual);
} else {
const expected = await fs.readFile(snapshot, 'utf8');
let expected;
try {
expected = await fs.readFile(snapshot, 'utf8');
} catch (e) {
if(e.code === 'ENOENT') {
console.log('Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1');
}
throw e;
}
assert.strictEqual(actual, replaceWindowsLineEndings(expected));
}
}
Expand Down

0 comments on commit 699f9c2

Please sign in to comment.