()
| 50 | * frame that isn't part of the expect module internals. |
| 51 | */ |
| 52 | export 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 |
no test coverage detected