Skip to content

Commit e70e974

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 f23b2a3 commit e70e974

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
@@ -34,7 +34,17 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
3434
if (process.env.NODE_REGENERATE_SNAPSHOTS) {
3535
await fs.writeFile(snapshot, actual);
3636
} else {
37-
const expected = await fs.readFile(snapshot, 'utf8');
37+
let expected;
38+
try {
39+
expected = await fs.readFile(snapshot, 'utf8');
40+
} catch (e) {
41+
if (e.code === 'ENOENT') {
42+
console.log(
43+
'Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1',
44+
);
45+
}
46+
throw e;
47+
}
3848
assert.strictEqual(actual, replaceWindowsLineEndings(expected));
3949
}
4050
}

0 commit comments

Comments
 (0)