Description
π Feature Proposal
Allowing passing custom colors/labels to jest-diff for use in the output.
Motivation
I'm using jest-diff in titanium-codemods, which is similar to react-codemod and uses jscodeshift to run transforms against code.
When a users asks for no files to be modified via the --dry-run
flag, I output any differences by diffing the modified source, and the original source. The current jest-diff looks a little strange when I do this as the added code is always colored red with +
, or green with -
depending on which way round I choose. Both of these match the jest ecosystem with snapshots but don't fit for anyone attempting to use jest-diff in a different context.
Showing changes for /Users/eharris/plainalloy/app/lib/appinfo_package.js
- After
+ Before
- `${Ti.App.name} ${Ti.App.version} ${Ti.Platform.name} ${Ti.Platform.version}`
+ `${Ti.App.getName()} ${Ti.App.getVersion()} ${Ti.Platform.getName()} ${Ti.Platform.getVersion()}`
Example
I would imagine this would be implemented as parameter in the diffOptions type for jest-diff. Maybe like below, which fits in with the existing API
const changes = diff(changedSource, original, {
aAnnotation: 'After',
aLabel: '+',
aColor: chalk.green,
bAnnotation: 'Before',
bLabel: '-',
bColor: chalk.red
});
I'm unsure however as to whether I like the aColor/bColor argument. It seems odd to me to tie this specifically to something like chalk, but I guess the typedef is just an argument that takes a string and transforms the string as desired not a specific recommendation.