Skip to content

Commit 3c4e98c

Browse files
rluvatonRafaelGSS
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 d3807a1 commit 3c4e98c

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
@@ -38,7 +38,17 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
3838
if (process.env.NODE_REGENERATE_SNAPSHOTS) {
3939
await fs.writeFile(snapshot, actual);
4040
} else {
41-
const expected = await fs.readFile(snapshot, 'utf8');
41+
let expected;
42+
try {
43+
expected = await fs.readFile(snapshot, 'utf8');
44+
} catch (e) {
45+
if (e.code === 'ENOENT') {
46+
console.log(
47+
'Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1',
48+
);
49+
}
50+
throw e;
51+
}
4252
assert.strictEqual(actual, replaceWindowsLineEndings(expected));
4353
}
4454
}

0 commit comments

Comments
 (0)