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 26, 2023
1 parent faefe56 commit f6cd240
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/common/assertSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ 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 f6cd240

Please sign in to comment.