From 1560417e6f1c000b132efd8708bf533305304e35 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sun, 5 Jun 2022 16:04:13 +0300 Subject: [PATCH] fix: don't escape quotes for objects in difference view (#1435) --- packages/vitest/src/node/diff.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/vitest/src/node/diff.ts b/packages/vitest/src/node/diff.ts index 037be5bb7c65..6a7c74bd5d6d 100644 --- a/packages/vitest/src/node/diff.ts +++ b/packages/vitest/src/node/diff.ts @@ -60,6 +60,7 @@ export function unifiedDiff(actual: string, expected: string, options: DiffOptio const isCompact = counts['+'] === 1 && counts['-'] === 1 && lines.length === 2 let formatted = lines.map((line: string) => { + line = line.replace(/\\"/g, '"') if (line[0] === '-') { line = formatLine(line.slice(1), outputTruncateLength) if (isCompact) @@ -86,6 +87,13 @@ export function unifiedDiff(actual: string, expected: string, options: DiffOptio ] } else { + if (formatted[0].includes('"')) + formatted[0] = formatted[0].replace('"', '') + + const last = formatted.length - 1 + if (formatted[last].endsWith('"')) + formatted[last] = formatted[last].slice(0, formatted[last].length - 1) + formatted.unshift( c.green(`- Expected - ${counts['-']}`), c.red(`+ Received + ${counts['+']}`),