MCPcopy Index your code
hub / github.com/nodejs/node / assertSnapshot

Function assertSnapshot

test/common/assertSnapshot.js:157–175  ·  view source on GitHub ↗
(actual, filename = process.argv[1])

Source from the content-addressed store, hash-verified

155}
156
157async function assertSnapshot(actual, filename = process.argv[1]) {
158 const snapshot = getSnapshotPath(filename);
159 if (process.env.NODE_REGENERATE_SNAPSHOTS) {
160 await fs.writeFile(snapshot, actual);
161 } else {
162 let expected;
163 try {
164 expected = await fs.readFile(snapshot, 'utf8');
165 } catch (e) {
166 if (e.code === 'ENOENT') {
167 console.log(
168 'Snapshot file does not exist. You can create a new one by running the test with NODE_REGENERATE_SNAPSHOTS=1',
169 );
170 }
171 throw e;
172 }
173 assert.strictEqual(actual, replaceWindowsLineEndings(expected));
174 }
175}
176
177/**
178 * Spawn a process and assert its output against a snapshot.

Callers 1

spawnAndAssertFunction · 0.85

Calls 5

getSnapshotPathFunction · 0.85
writeFileMethod · 0.45
readFileMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…