Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(snapshot): normalize EOL for toMatchFileSnapshot #3164

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/snapshot/src/port/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
addExtraLineBreaks,
getSnapshotData,
keyToTestName,
normalizeNewlines,
prepareExpected,
removeExtraLineBreaks,
saveSnapshotFile,
Expand Down Expand Up @@ -244,6 +245,12 @@ export default class SnapshotState {
if (!rawSnapshot)
receivedSerialized = addExtraLineBreaks(receivedSerialized)

if (rawSnapshot) {
// normalize EOL when snapshot contains CRLF but received is LF
if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/))
rawSnapshot.content = normalizeNewlines(rawSnapshot.content)
}

const expected = isInline
? inlineSnapshot
: rawSnapshot
Expand Down
2 changes: 1 addition & 1 deletion packages/snapshot/src/port/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function ensureDirectoryExists(environment: SnapshotEnvironment, fi
catch { }
}

function normalizeNewlines(string: string) {
export function normalizeNewlines(string: string) {
return string.replace(/\r\n|\r/g, '\n')
}

Expand Down