Skip to content

Commit bb9fd12

Browse files
committed
fix: preserve snapshot indentation in diff formatter
1 parent 725f460 commit bb9fd12

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/__tests__/cli-diff.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ test('diff snapshot renders human-readable unified diff text', async () => {
7676
const result = await runCliCapture(['diff', 'snapshot']);
7777
assert.equal(result.code, null);
7878
assert.equal(result.calls.length, 1);
79-
assert.match(result.stdout, /^ @e2 \[window\]/m);
80-
assert.match(result.stdout, /^- @e3 \[text\] "67"$/m);
81-
assert.match(result.stdout, /^\+ @e3 \[text\] "134"$/m);
79+
assert.match(result.stdout, /^@e2 \[window\]/m);
80+
assert.match(result.stdout, /^- @e3 \[text\] "67"$/m);
81+
assert.match(result.stdout, /^\+ @e3 \[text\] "134"$/m);
8282
assert.match(result.stdout, /1 additions, 1 removals, 1 unchanged/);
8383
assert.equal(result.stderr, '');
8484
});

src/utils/__tests__/output.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ test('formatSnapshotDiffText renders unified diff lines with summary', () => {
1919
});
2020

2121
assert.doesNotMatch(text, /^@e0 \[application\]$/m);
22-
assert.match(text, /^ @e2 \[window\]/m);
23-
assert.match(text, /^- @e3 \[other\] "67"$/m);
24-
assert.match(text, /^\+ @e3 \[other\] "134"$/m);
22+
assert.match(text, /^@e2 \[window\]/m);
23+
assert.match(text, /^- @e3 \[other\] "67"$/m);
24+
assert.match(text, /^\+ @e3 \[other\] "134"$/m);
2525
assert.match(text, /^ @e5 \[button\] "Increment"$/m);
2626
assert.doesNotMatch(text, /^ @e6 \[text\] "Footer"$/m);
2727
assert.match(text, /2 additions, 2 removals, 4 unchanged/);

src/utils/output.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ export function formatSnapshotDiffText(data: Record<string, unknown>): string {
8787
const contextLines = applyContextWindow(rawLines, 1);
8888
const lines = contextLines.map((line) => {
8989
const text = typeof line.text === 'string' ? line.text : '';
90-
if (line.kind === 'added') return `+ ${text.trimStart()}`;
91-
if (line.kind === 'removed') return `- ${text.trimStart()}`;
92-
return ` ${text.trimStart()}`;
90+
if (line.kind === 'added') return text.startsWith(' ') ? `+${text}` : `+ ${text}`;
91+
if (line.kind === 'removed') return text.startsWith(' ') ? `-${text}` : `- ${text}`;
92+
return text;
9393
});
9494
const body = lines.length > 0 ? `${lines.join('\n')}\n` : '';
9595
return `${body}${additions} additions, ${removals} removals, ${unchanged} unchanged\n`;

0 commit comments

Comments
 (0)