Skip to content

Commit

Permalink
fix: don't fail when there is no source file defined in source map (#…
Browse files Browse the repository at this point in the history
…1453)

* fix: don't fail when there is no source file, defined in source map

* chore: cleanup
  • Loading branch information
sheremet-va committed Jun 9, 2022
1 parent f0c24e0 commit 03c7cf6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/vitest/src/node/error.ts
Expand Up @@ -50,8 +50,13 @@ export async function printError(error: unknown, ctx: Vitest, options: PrintErro
printErrorMessage(e, ctx.console)
printStack(ctx, stacks, nearest, errorProperties, (s, pos) => {
if (showCodeFrame && s === nearest && nearest) {
const sourceCode = readFileSync(fileFromParsedStack(nearest), 'utf-8')
ctx.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)))
const file = fileFromParsedStack(nearest)
// could point to non-existing original file
// for example, when there is a source map file, but no source in node_modules
if (existsSync(file)) {
const sourceCode = readFileSync(file, 'utf-8')
ctx.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)))
}
}
})

Expand Down

0 comments on commit 03c7cf6

Please sign in to comment.