Skip to content

Commit a2ca1a6

Browse files
rluvatontargos
authored andcommitted
test: print instruction for creating missing snapshot in assertSnapshot
PR-URL: #48914 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 7778e19 commit a2ca1a6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/common/assertSnapshot.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,17 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
4242
if (process.env.NODE_REGENERATE_SNAPSHOTS) {
4343
await fs.writeFile(snapshot, actual);
4444
} else {
45-
const expected = await fs.readFile(snapshot, 'utf8');
45+
let expected;
46+
try {
47+
expected = await fs.readFile(snapshot, 'utf8');
48+
} catch (e) {
49+
if (e.code === 'ENOENT') {
50+
console.log(
51+
'Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1',
52+
);
53+
}
54+
throw e;
55+
}
4656
assert.strictEqual(actual, replaceWindowsLineEndings(expected));
4757
}
4858
}

0 commit comments

Comments
 (0)