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

Method createFileAssert

lib/internal/test_runner/snapshot.js:212–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

210 }
211
212 createFileAssert() {
213 const manager = this;
214
215 return function fileSnapshotAssertion(actual, path, options = kEmptyObject) {
216 validateString(path, 'path');
217 validateObject(options, 'options');
218 const {
219 serializers = serializerFns,
220 } = options;
221 validateFunctionArray(serializers, 'options.serializers');
222 const value = manager.serializeWithoutEscape(actual, serializers);
223
224 if (manager.updateSnapshots) {
225 try {
226 mkdirSync(dirname(path), { __proto__: null, recursive: true });
227 writeFileSync(path, value, 'utf8');
228 } catch (err) {
229 throwWriteError(err, path);
230 }
231 } else {
232 let expected;
233
234 try {
235 expected = readFileSync(path, 'utf8');
236 } catch (err) {
237 throwReadError(err, path);
238 }
239
240 strictEqual(value, expected);
241 }
242 };
243 }
244}
245
246function throwReadError(err, filename) {

Callers 1

lazyAssertObjectFunction · 0.80

Calls 8

validateFunctionArrayFunction · 0.85
dirnameFunction · 0.85
writeFileSyncFunction · 0.85
throwWriteErrorFunction · 0.85
throwReadErrorFunction · 0.85
mkdirSyncFunction · 0.50
readFileSyncFunction · 0.50

Tested by

no test coverage detected