Skip to content

Commit cdbd15e

Browse files
authored
chore: support print full error stack in debug mode (#525)
1 parent 7656856 commit cdbd15e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/core/src/utils/error.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs';
22
import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping';
33
import { type StackFrame, parse as stackTraceParse } from 'stacktrace-parser';
44
import type { FormattedError, GetSourcemap } from '../types';
5-
import { color, formatTestPath, logger } from '../utils';
5+
import { color, formatTestPath, isDebug, logger } from '../utils';
66

77
export async function printError(
88
error: FormattedError,
@@ -109,13 +109,13 @@ const stackIgnores: (RegExp | string)[] = [
109109
export async function parseErrorStacktrace({
110110
stack,
111111
getSourcemap,
112-
fullStack,
112+
fullStack = isDebug(),
113113
}: {
114114
fullStack?: boolean;
115115
stack: string;
116116
getSourcemap: GetSourcemap;
117117
}): Promise<StackFrame[]> {
118-
return Promise.all(
118+
const stackFrames = await Promise.all(
119119
stackTraceParse(stack)
120120
.filter((frame) =>
121121
fullStack
@@ -149,4 +149,12 @@ export async function parseErrorStacktrace({
149149
).then((frames) =>
150150
frames.filter((frame): frame is StackFrame => frame !== null),
151151
);
152+
153+
if (!stackFrames.length && stack.length) {
154+
logger.log(
155+
color.gray("No error stack found, set 'DEBUG=rstest' to show fullStack."),
156+
);
157+
}
158+
159+
return stackFrames;
152160
}

0 commit comments

Comments
 (0)