-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(snapshot): preserve white space of
toMatchFileSnapshot
(#7156)
- Loading branch information
Showing
8 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
white space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
example: | | ||
{ | ||
echo "hello" | ||
} | ||
some: | ||
nesting: | ||
- "hello world" | ||
even: | ||
more: | ||
nesting: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { join } from 'node:path' | ||
import { expect, test } from 'vitest' | ||
import { editFile, runVitest } from '../../test-utils' | ||
|
||
test('white space sensitive', async () => { | ||
const root = join(import.meta.dirname, 'fixtures/file') | ||
|
||
// check correct snapshot | ||
let vitest = await runVitest({ root }) | ||
expect(vitest.exitCode).toBe(0) | ||
|
||
// check diff of wrong snapshot | ||
editFile(join(root, 'snapshot-1.txt'), s => s.trim()) | ||
editFile(join(root, 'snapshot-2.txt'), s => s.replace('echo', 'ECHO')) | ||
vitest = await runVitest({ root }) | ||
expect(vitest.stderr).toContain(` | ||
- white space | ||
+ | ||
+ | ||
+ white space | ||
+ | ||
`) | ||
expect(vitest.stderr).toContain(` | ||
- ECHO "hello" | ||
+ echo "hello" | ||
`) | ||
expect(vitest.exitCode).toBe(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { test, expect } from "vitest" | ||
|
||
// pnpm -C test/snapshots test:fixtures --root test/fixtures/file | ||
|
||
test('white space', async () => { | ||
await expect(` | ||
white space | ||
`).toMatchFileSnapshot('snapshot-1.txt') | ||
}) | ||
|
||
test('indent', async () => { | ||
await expect(`\ | ||
example: | | ||
{ | ||
echo "hello" | ||
} | ||
some: | ||
nesting: | ||
- "hello world" | ||
even: | ||
more: | ||
nesting: true | ||
`).toMatchFileSnapshot('snapshot-2.txt') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
white space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
example: | | ||
{ | ||
echo "hello" | ||
} | ||
some: | ||
nesting: | ||
- "hello world" | ||
even: | ||
more: | ||
nesting: true |