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

[ON HOLD] - Add contextLines as option #6

Merged
merged 1 commit into from
Aug 1, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/__snapshots__/snapshotDiff.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ exports[`can expand diff 1`] = `
script"
`;

exports[`can use contextLines on diff 1`] = `
"- First value
+ Second value


some
some
some
some
some
some
some
not
+ so
very
long
script"
`;

exports[`collapses diffs and strips ansi by default 1`] = `
"- First value
+ Second value
Expand Down
4 changes: 4 additions & 0 deletions __tests__/snapshotDiff.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ test('can colorize diff', () => {
expect(snapshotDiff(a, b, {colors: true})).toMatchSnapshot();
});

test('can use contextLines on diff', () => {
expect(snapshotDiff(a, b, {contextLines: 0})).toMatchSnapshot();
});

test('diffs short strings', () => {
const x = `
abcx
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const reactElement = Symbol.for('react.element');

type Options = {
expand?: boolean,
colors?: boolean
colors?: boolean,
contextLines?: number,
};

const defaultOptions = {
expand: false,
colors: false
colors: false,
contextLines: -1, // Forces to use default from Jest
};

const snapshotDiff = (
Expand Down Expand Up @@ -42,6 +44,7 @@ const isReactComponent = valueA => valueA && valueA.$$typeof === reactElement;
function diffStrings(valueA, valueB, options) {
return diff(valueA, valueB, {
expand: options.expand,
contextLines: options.contextLines,
aAnnotation: 'First value',
bAnnotation: 'Second value'
});
Expand All @@ -55,6 +58,7 @@ function diffReactComponents(valueA, valueB, options) {

return diff(reactValueA, reactValueB, {
expand: options.expand,
contextLines: options.contextLines,
aAnnotation: prettyFormat(valueA, prettyFormatOptions),
bAnnotation: prettyFormat(valueB, prettyFormatOptions)
});
Expand Down