Skip to content

Commit

Permalink
fix: don't show __vite_ssr prefix on imported variables (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 8, 2022
1 parent 21e5827 commit a2f17b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/vitest/src/node/pool.ts
Expand Up @@ -14,7 +14,6 @@ export type RunWithFiles = (files: string[], invalidates?: string[]) => Promise<

export interface WorkerPool {
runTests: RunWithFiles
collectTests: RunWithFiles
close: () => Promise<void>
}

Expand Down Expand Up @@ -51,7 +50,6 @@ export function createFakePool(ctx: Vitest): WorkerPool {

return {
runTests: runWithFiles('run'),
collectTests: runWithFiles('collect'),
close: async () => {},
}
}
Expand Down Expand Up @@ -100,7 +98,6 @@ export function createWorkerPool(ctx: Vitest): WorkerPool {

return {
runTests: runWithFiles('run'),
collectTests: runWithFiles('collect'),
close: async () => {}, // TODO: not sure why this will cause Node crash: pool.destroy(),
}
}
Expand Down
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 a2f17b0

Please sign in to comment.