Skip to content

Commit

Permalink
test: print instruction for creating missing snapshot in assertSnapshot
Browse files Browse the repository at this point in the history
PR-URL: nodejs#48914
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
rluvaton authored and Ceres6 committed Aug 14, 2023
1 parent 1f60532 commit 0697014
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 @@ -38,7 +38,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 0697014

Please sign in to comment.