Skip to content

Commit

Permalink
fix: don't show __vite_ssr prefix on imported variables inside error …
Browse files Browse the repository at this point in the history
…mesage
  • Loading branch information
sheremet-va committed May 8, 2022
1 parent 5199e84 commit 1326df8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/vitest/src/runtime/error.ts
Expand Up @@ -49,6 +49,10 @@ export function serializeError(val: any, seen = new WeakMap()): any {
}
}

function normalizeErrorMessage(message: string) {
return message.replace(/__vite_ssr_import_\d+__\./g, '')
}

export function processError(err: any) {
if (!err)
return err
Expand All @@ -71,6 +75,13 @@ export function processError(err: any) {
err.expected = stringify(err.expected)
if (typeof err.actual !== 'string')
err.actual = stringify(err.actual)

if (typeof err.message === 'string')
err.message = normalizeErrorMessage(err.message)

if (typeof err.cause === 'object' && err.cause.message === 'string')
err.cause.message = normalizeErrorMessage(err.cause.message)

try {
return serializeError(err)
}
Expand Down

0 comments on commit 1326df8

Please sign in to comment.