diff --git a/src/nrepl/cider.ts b/src/nrepl/cider.ts index 5c0e23a0c..7a4f69425 100644 --- a/src/nrepl/cider.ts +++ b/src/nrepl/cider.ts @@ -1,3 +1,4 @@ +import { diff } from 'semver'; // https://github.com/clojure-emacs/cider-nrepl/blob/a740583c3aa8b582f3097611787a276775131d32/src/cider/nrepl/middleware/test.clj#L45 export interface TestSummary { ns: number; @@ -142,6 +143,24 @@ export function lineInformation(result: TestResult): string { return ` (${result.file}:${result.line})`; } +function testDiffInformation(result: TestResult): string[] { + const diffs = result.diffs; + const messages: string[] = []; + + if (diffs && Array.isArray(diffs)) { + diffs.forEach((diffPair: [string, string]) => { + if (Array.isArray(diffPair) && diffPair.length === 2) { + messages.push(`; expected:\n${diffPair[0]}`); + messages.push(`; actual:\n${diffPair[1]}`); + } else { + console.warn('Invalid diff pair format:', diffPair); + } + }); + } + + return messages; +} + // Return a detailed message about why a test failed. // If the test passed, return the empty string. // The message contains "comment" lines that are prepended with ; @@ -167,11 +186,18 @@ export function detailedMessage(result: TestResult): string | undefined { if (message) { messages.push(`; ${message}`); } - if (result.expected) { - messages.push(`; expected:\n${result.expected}`); - } - if (result.actual) { - messages.push(`; actual:\n${result.actual}`); + + const diffMessages = testDiffInformation(result); + + if (diffMessages.length > 0) { + messages.push(...diffMessages); + } else { + if (result.expected) { + messages.push(`; expected:\n${result.expected}`); + } + if (result.actual) { + messages.push(`; actual:\n${result.actual}`); + } } } return messages.length > 0 ? messages.join('\n') : undefined; diff --git a/src/testRunner.ts b/src/testRunner.ts index a929ca1b9..c02a337fe 100644 --- a/src/testRunner.ts +++ b/src/testRunner.ts @@ -139,6 +139,7 @@ async function onTestResult( run.errored(assertion, new vscode.TestMessage(cider.shortMessage(result))); break; case 'fail': + run.failed(assertion, new vscode.TestMessage(cider.detailedMessage(result))); default: run.failed(assertion, new vscode.TestMessage(cider.shortMessage(result))); break;