diff --git a/src/runner/runner.ts b/src/runner/runner.ts index 51d997f..138349d 100644 --- a/src/runner/runner.ts +++ b/src/runner/runner.ts @@ -507,7 +507,7 @@ function testMessageForTestError(testItem: vscode.TestItem, error: TestError | u else testMessage = new vscode.TestMessage(stripVTControlCharacters(error.message) ?? '') - testMessage.stackTrace = parseMessageStackFramesFromErrorStacks(error.stacks) + setMessageStackFramesFromErrorStacks(testMessage, error.stacks) const location = parseLocationFromStacks(testItem, error.stacks ?? []) if (location) { @@ -552,15 +552,22 @@ function parseLocationFromStacks(testItem: vscode.TestItem, stacks: ParsedStack[ log.verbose?.('Could not find a valid stack for', testItem.label, JSON.stringify(stacks, null, 2)) } -function parseMessageStackFramesFromErrorStacks(stacks: ParsedStack[] | undefined): vscode.TestMessageStackFrame[] | undefined { +function setMessageStackFramesFromErrorStacks(testMessage: vscode.TestMessage, stacks: ParsedStack[] | undefined) { + // Error stack frames are available only in ^1.93 + if (!('TestMessageStackFrame' in vscode)) + return if (!stacks || stacks.length === 0) - return undefined + return + + const TestMessageStackFrame = (vscode as any).TestMessageStackFrame - return stacks.map((stack) => { + const frames = stacks.map((stack) => { const { sourceFilepath, line, column } = getSourceFilepathAndLocationFromStack(stack) const sourceUri = sourceFilepath ? vscode.Uri.file(sourceFilepath) : undefined - return new vscode.TestMessageStackFrame(stack.method, sourceUri, new vscode.Position(line - 1, column - 1)) - }) + return new TestMessageStackFrame(stack.method, sourceUri, new vscode.Position(line - 1, column - 1)) + }); + + (testMessage as any).stackTrace = frames } function getTestFiles(tests: readonly vscode.TestItem[]): string[] | SerializedTestSpecification[] {