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

Function getTestFileFromStack

expect/_snapshot_state.ts:52–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50 * frame that isn't part of the expect module internals.
51 */
52export function getTestFileFromStack(): string | null {
53 // deno-lint-ignore no-explicit-any
54 const ErrorCtor = Error as any;
55 const origPrepareStackTrace = ErrorCtor.prepareStackTrace;
56 try {
57 const obj: { stack: string | null } = { stack: null };
58 ErrorCtor.prepareStackTrace = (
59 _err: Error,
60 // deno-lint-ignore no-explicit-any
61 stack: any[],
62 ): string | null => {
63 for (const frame of stack) {
64 if (frame.isEval()) continue;
65 const fileName: string | null = frame.getFileName();
66 if (fileName === null) continue;
67 // Skip expect module internal files
68 if (
69 fileName.includes("/expect/_") ||
70 fileName.includes("/expect/expect.ts")
71 ) {
72 continue;
73 }
74 return fileName;
75 }
76 return null;
77 };
78 ErrorCtor.captureStackTrace(obj);
79 return obj.stack;
80 } finally {
81 ErrorCtor.prepareStackTrace = origPrepareStackTrace;
82 }
83}
84
85// --- Serialization ---
86

Callers 1

toMatchSnapshotFunction · 0.90

Calls 3

isEvalMethod · 0.80
getFileNameMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected