From e70e9747e447341289941b684c1ca2fbb3b55f9b Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Fri, 11 Aug 2023 11:17:53 +0300 Subject: [PATCH] test: print instruction for creating missing snapshot in assertSnapshot PR-URL: https://github.com/nodejs/node/pull/48914 Reviewed-By: Moshe Atlow Reviewed-By: Benjamin Gruenbaum --- test/common/assertSnapshot.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/common/assertSnapshot.js b/test/common/assertSnapshot.js index 10a5941b41ff37..da6952ba1204ee 100644 --- a/test/common/assertSnapshot.js +++ b/test/common/assertSnapshot.js @@ -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)); } }