From 2f37ccea854b6d10901c42a1fcde450ded6cba01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nagy=20M=C3=A1t=C3=A9?= Date: Sun, 2 Nov 2025 10:49:33 +0100 Subject: [PATCH] docs: Improve `onStackTrace` docs to include limitations and tips (#8905) --- docs/config/index.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index b3430ec64..a2043a15b 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -1927,17 +1927,21 @@ export default defineConfig({ - **Type**: `(error: Error, frame: ParsedStack) => boolean | void` -Apply a filtering function to each frame of each stack trace when handling errors. The first argument, `error`, is an object with the same properties as a standard `Error`, but it is not an actual instance. +Apply a filtering function to each frame of each stack trace when handling errors. This does not apply to stack traces printed by [`printConsoleTrace`](#printConsoleTrace). The first argument, `error`, is a `TestError`. Can be useful for filtering out stack trace frames from third-party libraries. +::: tip +The stack trace's total size is also typically limited by V8's [`Error.stackTraceLimit`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/stackTraceLimit) number. You could set this to a high value in your test setup function to prevent stacks from being truncated. +::: + ```ts -import type { ParsedStack } from 'vitest' +import type { ParsedStack, TestError } from 'vitest' import { defineConfig } from 'vitest/config' export default defineConfig({ test: { - onStackTrace(error: Error, { file }: ParsedStack): boolean | void { + onStackTrace(error: TestError, { file }: ParsedStack): boolean | void { // If we've encountered a ReferenceError, show the whole stack. if (error.name === 'ReferenceError') { return -- 2.51.2