From f6cd240e8cb9ad48fb74655a554d14a9a1e65278 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:30:30 +0300 Subject: [PATCH] test: when snapshot is missing print how to generate one --- 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 c403751ac3ef5e..313b06653097c0 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)); } }