From dad9498b8f6392343da1443d0f7913ec63216126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Weslley=20Ara=C3=BAjo?= <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 1 Mar 2024 08:22:45 -0300 Subject: [PATCH] fix(bun): file path is not parsed (#58) --- src/helpers/parseAsssetion.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/helpers/parseAsssetion.ts b/src/helpers/parseAsssetion.ts index 26aca330..a927e414 100644 --- a/src/helpers/parseAsssetion.ts +++ b/src/helpers/parseAsssetion.ts @@ -23,11 +23,21 @@ const findFile = (error: Error) => { for (const line of stackLines) { if (!line.includes(basePath)) { - const match = line.match(/at\s(\/.+|file:\/\/\/.+)/i); + const match = line.match( + /at\s(\/.+|file:.+)|^(\s+)at\smodule\scode\s\((\/.+|file:.+)\)/i + ); + + // Node and Deno if (match && match[1]) { file = match[1]; break; } + + // Bun + if (match && match[3]) { + file = match[3]; + break; + } } } @@ -57,7 +67,7 @@ export const parseAssertion = ( } catch (error) { if (error instanceof assert.AssertionError) { const { code, actual, expected, operator } = error; - const absoultePath = findFile(error); + const absoultePath = findFile(error).replace(/file:/, ''); const file = path.relative(path.resolve(process.cwd()), absoultePath); let message: string = '';