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-diff: Add firstOrLastEmptyLineReplacement option and export 3 diffLines functions #8955

Merged

Conversation

pedrottimark
Copy link
Contributor

Summary

  1. replace another hard-coded string with an option

  2. export diffLinesUnified2 which jest-snapshot will need to ignore indentation

  3. delete redundant code to reduce inconsistent behavior

Because diffLines.ts is completely re-written, you might see if Split view is easier to review

Test plan

diffs.test.ts

  • added 2 new tests to confirm that default export was inconsistent
  • updated 4 tests for empty line to automatically trim space in default export

printDiffOrStringified.test.ts.snap

  • updated 1 snapshot for empty line to automatically trim space in default export

@pedrottimark
Copy link
Contributor Author

Examples for the next pull request reminded me of problems in edge cases because ''.split('\n') returns [''] instead of empty array:

  • added splitLines0 as a named export
  • refactored diffStringsUnified to call diffLinesUnified for edge cases of all common or no common to make sure that the difference is consistent (for example, the baseline code for all common ignored the expand: false option)

To avoid too much chaos in Changed Files I will leave as a future chore to move diffStringsUnified and diffStringsRaw from the printDiffs.ts file to the diffStrings.ts file, which seems more intuitive

packages/jest-diff/src/diffLines.ts Show resolved Hide resolved
packages/jest-diff/src/types.ts Outdated Show resolved Hide resolved
@pedrottimark pedrottimark changed the title jest-diff: Add trimmableLineReplacement option and export 3 diffLines functions jest-diff: Add firstOrLastEmptyLineReplacement option and export 3 diffLines functions Sep 21, 2019
@codecov-io
Copy link

Codecov Report

Merging #8955 into master will decrease coverage by 0.22%.
The diff coverage is 96.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8955      +/-   ##
==========================================
- Coverage    64.2%   63.98%   -0.23%     
==========================================
  Files         276      276              
  Lines       11718    11638      -80     
  Branches     2868     2858      -10     
==========================================
- Hits         7523     7446      -77     
+ Misses       3563     3562       -1     
+ Partials      632      630       -2
Impacted Files Coverage Δ
packages/jest-diff/src/normalizeDiffOptions.ts 100% <ø> (ø) ⬆️
packages/jest-diff/src/printDiffs.ts 100% <100%> (+2.59%) ⬆️
packages/jest-diff/src/joinAlignedDiffs.ts 100% <100%> (ø) ⬆️
packages/jest-diff/src/diffLines.ts 95.23% <95.12%> (-1.54%) ⬇️
packages/jest-diff/src/index.ts 81.48% <96.15%> (+3.43%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1693028...a470d56. Read the comment docs.

Copy link
Contributor

@jeysal jeysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda hard to review such a big change, but since the test changes seem ok, the code looks simpler, and there's no red flags, lgtm 😄

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants