diff --git a/packages/vitest/src/node/state.ts b/packages/vitest/src/node/state.ts index b394992a27f6..54dc6ea31d40 100644 --- a/packages/vitest/src/node/state.ts +++ b/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 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() @@ -14,7 +23,10 @@ export class StateManager { taskFileMap = new WeakMap() errorsSet = new Set() - 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) } diff --git a/packages/vitest/src/runtime/setup.ts b/packages/vitest/src/runtime/setup.ts index 73b3b2491e6a..61c1a17848b4 100644 --- a/packages/vitest/src/runtime/setup.ts +++ b/packages/vitest/src/runtime/setup.ts @@ -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)