Skip to content

Commit

Permalink
Fix file:// URLs handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed May 17, 2024
1 parent 2ff9854 commit c3d5ddd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/earl/src/errors/AssertionError.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fileURLToPath } from 'node:url'
import ErrorStackParser from 'error-stack-parser'

interface AssertionErrorOptions {
Expand Down Expand Up @@ -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
},
Expand Down
5 changes: 5 additions & 0 deletions packages/earl/src/validators/snapshots/TestContext.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fileURLToPath } from 'node:url'

export type TestContext = NodeTestContext | MochaTestContext | UvuTestContext

export interface NodeTestContext {
Expand All @@ -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
}
}
Expand Down

0 comments on commit c3d5ddd

Please sign in to comment.