File tree Expand file tree Collapse file tree
packages/snapshot/src/port Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,7 +90,8 @@ export function serialize(
9090}
9191
9292function escapeBacktickString ( str : string ) : string {
93- return str . replace ( / ` | \\ | \$ \{ / g, '\\$&' )
93+ // a raw CR inside a template literal is read back as LF
94+ return str . replace ( / ` | \\ | \$ \{ / g, '\\$&' ) . replace ( / \r / g, '\\r' )
9495}
9596
9697function printBacktickString ( str : string ) : string {
Original file line number Diff line number Diff line change @@ -111,3 +111,52 @@ test.fails('soft', () => {
111111 }
112112 ` )
113113} )
114+
115+ test ( 'test names with line endings match their snapshots on the next run' , async ( ) => {
116+ const result = await runInlineTests (
117+ {
118+ 'basic.test.ts' : `
119+ import { expect, test } from 'vitest'
120+
121+ test.for(['a\\nb', 'a\\r\\nb', 'a\\rb'])('%s', (input) => {
122+ expect(input.length).toMatchSnapshot()
123+ })
124+ ` ,
125+ } ,
126+ { update : 'new' } ,
127+ )
128+ expect ( result . stderr ) . toBe ( '' )
129+ expect ( result . fs . readFile ( '__snapshots__/basic.test.ts.snap' ) ) . toMatchInlineSnapshot ( `
130+ "// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
131+
132+ exports[\`a
133+ b 1\`] = \`3\`;
134+
135+ exports[\`a\\r
136+ b 1\`] = \`4\`;
137+
138+ exports[\`a\\rb 1\`] = \`3\`;
139+ "
140+ ` )
141+
142+ const rerun = await runVitest ( { root : result . root , update : 'none' } )
143+ expect ( rerun . stderr ) . toBe ( '' )
144+ expect ( rerun . ctx ?. snapshot . summary ) . toMatchInlineSnapshot ( `
145+ {
146+ "added": 0,
147+ "didUpdate": false,
148+ "failure": false,
149+ "filesAdded": 0,
150+ "filesRemoved": 0,
151+ "filesRemovedList": [],
152+ "filesUnmatched": 0,
153+ "filesUpdated": 0,
154+ "matched": 3,
155+ "total": 3,
156+ "unchecked": 0,
157+ "uncheckedKeysByFile": [],
158+ "unmatched": 0,
159+ "updated": 0,
160+ }
161+ ` )
162+ } )
You can’t perform that action at this time.
0 commit comments