Skip to content

Commit 699f9c2

Browse files
committed
test: when snapshot is missing print how to generate one
1 parent a0f3ed8 commit 699f9c2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/common/assertSnapshot.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ 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('Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1');
43+
}
44+
throw e;
45+
}
3846
assert.strictEqual(actual, replaceWindowsLineEndings(expected));
3947
}
4048
}

0 commit comments

Comments
 (0)