Skip to content

Commit

Permalink
hotfix for adding stack traces for error as the feature was added onl…
Browse files Browse the repository at this point in the history
…y in vscode 1.93 (#546)
  • Loading branch information
ArthurHub authored Nov 28, 2024
1 parent cdca42f commit 375c94a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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[] {
Expand Down

0 comments on commit 375c94a

Please sign in to comment.