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

jest-snapshot: Fix regression in diff for jest-snapshot-serializer-raw #9419

Merged
merged 3 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
- `[jest-snapshot]` [**BREAKING**] Distinguish empty string from internal snapshot not written ([#8898](https://github.com/facebook/jest/pull/8898))
- `[jest-snapshot]` [**BREAKING**] Remove `report` method and throw matcher errors ([#9049](https://github.com/facebook/jest/pull/9049))
- `[jest-snapshot]` Omit irrelevant `received` properties when property matchers fail ([#9198](https://github.com/facebook/jest/pull/9198))
- `[jest-snapshot]` Fix regression in diff for `jest-snapshot-serializer-raw` ([#9419](https://github.com/facebook/jest/pull/9419))
pedrottimark marked this conversation as resolved.
Show resolved Hide resolved
- `[jest-transform]` Properly cache transformed files across tests ([#8890](https://github.com/facebook/jest/pull/8890))
- `[jest-transform]` Don't fail the test suite when a generated source map is invalid ([#9058](https://github.com/facebook/jest/pull/9058))
- `[jest-types]` [**BREAKING**] Use less `null | undefined` in config types ([#9200](https://github.com/facebook/jest/pull/9200))
Expand Down
16 changes: 11 additions & 5 deletions packages/jest-snapshot/src/printSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,18 @@ export const printSnapshotAndReceived = (
const aLines2 = a.split('\n');
const bLines2 = b.split('\n');

const aLines0 = dedentLines(aLines2);
// Fall through to fix a regression for custom serializers
// like jest-snapshot-serializer-raw that ignore the indent option.
const b0 = serialize(received, 0);
if (b0 !== b) {
const aLines0 = dedentLines(aLines2);

if (aLines0 !== null) {
// Compare lines without indentation.
const bLines0 = serialize(received, 0).split('\n');
return diffLinesUnified2(aLines2, bLines2, aLines0, bLines0, options);
if (aLines0 !== null) {
// Compare lines without indentation.
const bLines0 = b0.split('\n');

return diffLinesUnified2(aLines2, bLines2, aLines0, bLines0, options);
}
}

// Fall back because:
Expand Down