From c3d5ddd0f0ab5d97bcc1acdfc9b72a34bf40347f Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Fri, 17 May 2024 21:55:29 +0000 Subject: [PATCH] Fix file:// URLs handling --- packages/earl/src/errors/AssertionError.ts | 3 ++- packages/earl/src/validators/snapshots/TestContext.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/earl/src/errors/AssertionError.ts b/packages/earl/src/errors/AssertionError.ts index 9b6d3e5e..5f0c7250 100644 --- a/packages/earl/src/errors/AssertionError.ts +++ b/packages/earl/src/errors/AssertionError.ts @@ -1,3 +1,4 @@ +import { fileURLToPath } from 'node:url' import ErrorStackParser from 'error-stack-parser' interface AssertionErrorOptions { @@ -34,7 +35,7 @@ export class AssertionError extends Error { parsed = parsed ?? ErrorStackParser.parse({ stack: cleaned } as Error) const fileName = parsed[0]?.fileName if (fileName?.startsWith('file://')) { - return fileName.slice(7) + return fileURLToPath(fileName) } return fileName }, diff --git a/packages/earl/src/validators/snapshots/TestContext.ts b/packages/earl/src/validators/snapshots/TestContext.ts index 70251f28..b1057af9 100644 --- a/packages/earl/src/validators/snapshots/TestContext.ts +++ b/packages/earl/src/validators/snapshots/TestContext.ts @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'node:url' + export type TestContext = NodeTestContext | MochaTestContext | UvuTestContext export interface NodeTestContext { @@ -20,6 +22,9 @@ export function getTestFile(context: TestContext): string | undefined { if ('test' in context) { const file = context.test?.file if (typeof file === 'string') { + if (file.startsWith('file://')) { + return fileURLToPath(file) + } return file } }