MCPcopy Create free account
hub / github.com/denoland/std / assertInlineSnapshot

Function assertInlineSnapshot

testing/unstable_snapshot.ts:218–272  ·  view source on GitHub ↗
(
  actual: unknown,
  expectedSnapshot: string,
  msgOrOpts?: string | InlineSnapshotOptions<unknown>,
)

Source from the content-addressed store, hash-verified

216 message?: string,
217): void;
218export function assertInlineSnapshot(
219 actual: unknown,
220 expectedSnapshot: string,
221 msgOrOpts?: string | InlineSnapshotOptions<unknown>,
222): void {
223 const options = getOptions(msgOrOpts);
224 const serializer = options.serializer ?? serialize;
225 const actualSnapshot = serializer(actual);
226 // TODO(WWRS): dedent expectedSnapshot to allow snapshots to look nicer
227
228 if (equal(actualSnapshot, expectedSnapshot)) {
229 return;
230 }
231
232 if (getIsUpdate(options)) {
233 const origPrepareStackTrace = (Error as V8Error).prepareStackTrace;
234 try {
235 const stackCatcher = { stack: null as SnapshotUpdateRequest | null };
236 (Error as V8Error).prepareStackTrace = (
237 _err: Error,
238 stack: CallSite[],
239 ): SnapshotUpdateRequest | null => {
240 const callerStackFrame = stack[0];
241 if (!callerStackFrame || callerStackFrame.isEval()) return null;
242
243 const fileName = callerStackFrame.getFileName();
244 const lineNumber = callerStackFrame.getLineNumber();
245 const columnNumber = callerStackFrame.getColumnNumber();
246 if (fileName === null || lineNumber === null || columnNumber === null) {
247 return null;
248 }
249
250 return {
251 fileName,
252 lineNumber,
253 columnNumber,
254 actualSnapshot,
255 };
256 };
257 // Capture the stack that comes after this function.
258 Error.captureStackTrace(stackCatcher, assertInlineSnapshot);
259 // Forcibly access the stack, and note it down
260 const request = stackCatcher.stack;
261 if (request !== null) {
262 updateRequests.push(request);
263 }
264 } finally {
265 (Error as V8Error).prepareStackTrace = origPrepareStackTrace;
266 }
267 } else {
268 throw new AssertionError(
269 getSnapshotNotMatchMessage(actualSnapshot, expectedSnapshot, options),
270 );
271 }
272}
273
274/**
275 * Create {@linkcode assertInlineSnapshot} function with the given options.

Callers 1

Calls 9

getOptionsFunction · 0.90
equalFunction · 0.90
getIsUpdateFunction · 0.90
isEvalMethod · 0.80
getFileNameMethod · 0.80
getLineNumberMethod · 0.80
getColumnNumberMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected