Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show stack trace for aggregated errors, show full stack trace #1777

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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