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: #48914
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
rluvaton authored and RafaelGSS committed Aug 17, 2023
1 parent f23b2a3 commit e70e974
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 e70e974

Please sign in to comment.