Skip to content

Commit

Permalink
feat: show stack trace for aggregated errors, show full stack trace (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 4, 2022
1 parent 5e6a8da commit 82a877c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/vitest/src/node/state.ts
@@ -1,10 +1,19 @@
import type { ErrorWithDiff, File, Task, TaskResultPack, UserConsoleLog } from '../types'
// can't import actual functions from utils, because it's incompatible with @vitest/browsers
import type { AggregateError as AggregateErrorPonyfill } from '../utils'

interface CollectingPromise {
promise: Promise<void>
resolve: () => void
}

export const isAggregateError = (err: unknown): err is AggregateErrorPonyfill => {
if (typeof AggregateError !== 'undefined' && err instanceof AggregateError)
return true

return err instanceof Error && 'errors' in err
}

// Note this file is shared for both node and browser, be aware to avoid node specific logic
export class StateManager {
filesMap = new Map<string, File>()
Expand All @@ -14,7 +23,10 @@ export class StateManager {
taskFileMap = new WeakMap<Task, File>()
errorsSet = new Set<unknown>()

catchError(err: unknown, type: string) {
catchError(err: unknown, type: string): void {
if (isAggregateError(err))
return err.errors.forEach(error => this.catchError(error, type));

(err as ErrorWithDiff).type = type
this.errorsSet.add(err)
}
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/runtime/setup.ts
Expand Up @@ -15,6 +15,9 @@ export async function setupGlobalEnv(config: ResolvedConfig) {
enumerable: false,
})

// it's useful to see the full stack trace in the console by default
Error.stackTraceLimit = 100

// should be re-declared for each test
// if run with "threads: false"
setupDefines(config.defines)
Expand Down

0 comments on commit 82a877c

Please sign in to comment.