MCPcopy
hub / github.com/jestjs/jest / saveSnapshotFile

Function saveSnapshotFile

packages/jest-snapshot-utils/src/utils.ts:182–200  ·  view source on GitHub ↗
(
  snapshotData: SnapshotData,
  snapshotPath: string,
)

Source from the content-addressed store, hash-verified

180 string.replaceAll(/\r\n|\r/g, '\n');
181
182export const saveSnapshotFile = (
183 snapshotData: SnapshotData,
184 snapshotPath: string,
185): void => {
186 const snapshots = Object.keys(snapshotData)
187 .sort(naturalCompare)
188 .map(
189 key =>
190 `exports[${printBacktickString(key)}] = ${printBacktickString(
191 normalizeNewlines(snapshotData[key]),
192 )};`,
193 );
194
195 ensureDirectoryExists(snapshotPath);
196 fs.writeFileSync(
197 snapshotPath,
198 `${writeSnapshotVersion()}\n\n${snapshots.join('\n\n')}\n`,
199 );
200};

Callers 2

utils.test.tsFile · 0.90
saveMethod · 0.90

Calls 5

printBacktickStringFunction · 0.85
normalizeNewlinesFunction · 0.85
ensureDirectoryExistsFunction · 0.85
writeSnapshotVersionFunction · 0.85
sortMethod · 0.45

Tested by

no test coverage detected