From 2b70f5213d0fb600b708e295ed76815b4cd1d21b Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Tue, 18 Oct 2022 17:32:38 +0100 Subject: [PATCH 1/2] Show stacktrace on test error Fixes #424 --- CHANGELOG.md | 2 ++ src/nrepl/index.ts | 18 ++++++++++++++++++ src/testRunner.ts | 12 ++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b760a8d2..d384f3175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Changes to Calva. ## [Unreleased] +- [Test runner does not show stacktrace on error](https://github.com/BetterThanTomorrow/calva/issues/424) + ## [2.0.307] - 2022-10-11 - [Support user level `~/.config/calva/config.edn`](https://github.com/BetterThanTomorrow/calva/issues/1887) diff --git a/src/nrepl/index.ts b/src/nrepl/index.ts index 945ebc85b..af01cde6a 100644 --- a/src/nrepl/index.ts +++ b/src/nrepl/index.ts @@ -515,6 +515,24 @@ export class NReplSession { }); } + testStacktrace(ns: string, test: string, index: number) { + return new Promise((resolve, reject) => { + let id = this.client.nextId; + this.messageHandlers[id] = (msg) => { + resolve(msg); + return true; + }; + this.client.write({ + op: 'test-stacktrace', + id, + session: this.sessionId, + ns, + var: test, + index: index, + }); + }); + } + testNs(ns: string) { return this.testVarQuery({ 'ns-query': { diff --git a/src/testRunner.ts b/src/testRunner.ts index 0c3195d63..4f2ff5e0c 100644 --- a/src/testRunner.ts +++ b/src/testRunner.ts @@ -168,7 +168,7 @@ function useTestExplorer(): boolean | undefined { return vscode.workspace.getConfiguration('calva').get('useTestExplorer'); } -function reportTests( +async function reportTests( controller: vscode.TestController, session: NReplSession, possibleResults: cider.TestResults[] @@ -208,7 +208,15 @@ function reportTests( cider.cleanUpWhiteSpace(a); const messages = cider.detailedMessage(a); - if (messages) { + + if (a.type == 'error') { + const stackTrace = await session.testStacktrace(ns, test, a.index); + + outputWindow.saveStacktrace(stackTrace.stacktrace); + outputWindow.append(messages, (_, afterResultLocation) => { + outputWindow.markLastStacktraceRange(afterResultLocation); + }); + } else if (messages) { outputWindow.append(messages); } From e0f447133d71f5ed0140f38b4c06a5a95f5353db Mon Sep 17 00:00:00 2001 From: Stephen Young Date: Wed, 19 Oct 2022 08:55:54 +0100 Subject: [PATCH 2/2] eslint fixes --- src/nrepl/index.ts | 2 +- src/testRunner.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nrepl/index.ts b/src/nrepl/index.ts index af01cde6a..395a63287 100644 --- a/src/nrepl/index.ts +++ b/src/nrepl/index.ts @@ -517,7 +517,7 @@ export class NReplSession { testStacktrace(ns: string, test: string, index: number) { return new Promise((resolve, reject) => { - let id = this.client.nextId; + const id = this.client.nextId; this.messageHandlers[id] = (msg) => { resolve(msg); return true; diff --git a/src/testRunner.ts b/src/testRunner.ts index 4f2ff5e0c..d86db5d24 100644 --- a/src/testRunner.ts +++ b/src/testRunner.ts @@ -245,7 +245,7 @@ async function runAllTests(controller: vscode.TestController, document = {}) { const session = getSession(util.getFileType(document)); outputWindow.append('; Running all project tests…'); try { - reportTests(controller, session, [await session.testAll()]); + await reportTests(controller, session, [await session.testAll()]); } catch (e) { outputWindow.append('; ' + e); } @@ -306,7 +306,7 @@ async function runNamespaceTestsImpl( return session.testNs(ns); }); try { - reportTests(controller, session, await Promise.all(resultPromises)); + await reportTests(controller, session, await Promise.all(resultPromises)); } catch (e) { outputWindow.append('; ' + e); } @@ -343,7 +343,7 @@ async function runTestUnderCursor(controller: vscode.TestController) { if (test) { outputWindow.append(`; Running test: ${test}…`); try { - reportTests(controller, session, [await session.test(ns, test)]); + await reportTests(controller, session, [await session.test(ns, test)]); } catch (e) { outputWindow.append('; ' + e); } @@ -381,7 +381,7 @@ async function rerunTests(controller: vscode.TestController, document = {}) { const session = getSession(util.getFileType(document)); outputWindow.append('; Running previously failed tests…'); try { - reportTests(controller, session, [await session.retest()]); + await reportTests(controller, session, [await session.retest()]); } catch (e) { outputWindow.append('; ' + e); }