Skip to content

Commit

Permalink
fix: don't escape quotes for objects in difference view (#1435)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 5, 2022
1 parent d5a5bbc commit 1560417
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/vitest/src/node/diff.ts
Expand Up @@ -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)
Expand All @@ -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['+']}`),
Expand Down

0 comments on commit 1560417

Please sign in to comment.