Skip to content

Commit

Permalink
Add contextLines as an option. (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrannp authored and thymikee committed Aug 1, 2017
1 parent a8787e2 commit a76eff3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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

0 comments on commit a76eff3

Please sign in to comment.