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 changeColor and patchColor options #8911

Merged
merged 6 commits into from
Sep 5, 2019

Conversation

pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Sep 4, 2019

Summary

Provide options for the remaining 2 hard-coded colors used by diffStringsUnified

Residue: the default export can output 2 additional hard-coded colors in edge cases:

  1. cyan for lines for which indentation is the only difference: will be superseded by ignoreIndentation option and no color distinction for such common lines
  2. bgYellow for leading or trailing spaces in common lines, because inverse of dim is invisible, but it is not clear that they need formatting

@thymikee after the residue has been solved, it seems like the default colors: false option in snapshot-diff package can replace strip-ansi with identity function for jest-diff color options

Test plan

Added 1 and updated 3 snapshots in diffs.test.ts.snap

Add string serializer to omit double quote marks and use options to omit line colors:

  • Updated 24 snapshots in getAlignedDiffs.test.ts.snap
  • Updated 6 snapshots in joinAlignedDiffs.test.ts.snap

See also pictures in the following comments

Baseline at left and optional at right

@pedrottimark
Copy link
Contributor Author

diffStringsUnified(a, b, options)
const options = {
  changeColor: chalk.bold.bgAnsi256(226), // #ffff00
};

change color

const identity = string => string;
const options = {
  aColor: identity,
  bColor: identity,
  changeColor: identity,
  commonColor: identity,
  contextLines: 1,
  expand: false,
  patchColor: identity,
};

no color

@pedrottimark
Copy link
Contributor Author

diffLinesUnified(a, b, options)
const options = {
  contextLines: 1,
  expand: false,
  patchColor: chalk.dim,
};

patch color

const identity = string => string;
const options = {
  aColor: identity,
  bColor: identity,
  changeColor: identity,
  commonColor: identity,
  contextLines: 1,
  expand: false,
  patchColor: identity,
};

Residue 1:

cyan

Residue 2:

bgYellow

@codecov-io
Copy link

codecov-io commented Sep 4, 2019

Codecov Report

Merging #8911 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8911      +/-   ##
==========================================
+ Coverage   64.24%   64.25%   +<.01%     
==========================================
  Files         275      275              
  Lines       11658    11657       -1     
  Branches     2846     2845       -1     
==========================================
  Hits         7490     7490              
  Misses       3544     3544              
+ Partials      624      623       -1
Impacted Files Coverage Δ
packages/jest-diff/src/normalizeDiffOptions.ts 100% <ø> (ø) ⬆️
packages/jest-diff/src/diffLines.ts 97.12% <100%> (ø) ⬆️
packages/jest-diff/src/printDiffs.ts 97.43% <100%> (+0.96%) ⬆️
packages/jest-diff/src/getAlignedDiffs.ts 100% <100%> (ø) ⬆️
packages/jest-diff/src/joinAlignedDiffs.ts 100% <100%> (ø) ⬆️

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 8e0786f...e5916a5. Read the comment docs.

packages/jest-diff/README.md Outdated Show resolved Hide resolved
@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