Skip to content

Commit

Permalink
fix(api): make api parse error stacks and return sourcePos in onTaskU…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
adrienbaron committed Dec 25, 2022
1 parent a431df8 commit 312fa95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vitest/src/api/setup.ts
@@ -1,4 +1,5 @@
import { promises as fs } from 'node:fs'

import type { BirpcReturn } from 'birpc'
import { createBirpc } from 'birpc'
import { parse, stringify } from 'flatted'
Expand All @@ -8,6 +9,7 @@ import { API_PATH } from '../constants'
import type { Vitest } from '../node'
import type { File, ModuleGraphData, Reporter, TaskResultPack, UserConsoleLog } from '../types'
import { getModuleGraph } from '../utils'
import { parseStacktrace } from '../utils/source-map'
import type { TransformResultWithSource, WebSocketEvents, WebSocketHandlers } from './types'

export function setup(ctx: Vitest) {
Expand Down Expand Up @@ -121,6 +123,11 @@ class WebSocketReporter implements Reporter {
if (this.clients.size === 0)
return

packs.forEach(([, result]) => {
if (result?.error)
result.error.stacks = parseStacktrace(result.error)
})

this.clients.forEach((client) => {
client.onTaskUpdate?.(packs)
})
Expand Down
5 changes: 5 additions & 0 deletions packages/vitest/src/utils/source-map.ts
Expand Up @@ -83,6 +83,11 @@ export function parseStacktrace(e: ErrorWithDiff, full = false): ParsedStack[] {
file,
line: parseInt(lineNumber),
column: parseInt(columnNumber),
sourcePos: {
source: file,
line: parseInt(lineNumber),
column: parseInt(columnNumber),
},
}
})
.filter(notNullish)
Expand Down

0 comments on commit 312fa95

Please sign in to comment.