Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a76eff3

Browse files
ferrannpthymikee
authored andcommitted
Add contextLines as an option. (#6)
1 parent a8787e2 commit a76eff3

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

‎__tests__/__snapshots__/snapshotDiff.test.js.snap‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ exports[`can expand diff 1`] = `
3838
script"
3939
`;
4040

41+
exports[`can use contextLines on diff 1`] = `
42+
"- First value
43+
+ Second value
44+
45+
46+
some
47+
some
48+
some
49+
some
50+
some
51+
some
52+
some
53+
not
54+
+ so
55+
very
56+
long
57+
script"
58+
`;
59+
4160
exports[`collapses diffs and strips ansi by default 1`] = `
4261
"- First value
4362
+ Second value

‎__tests__/snapshotDiff.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ test('can colorize diff', () => {
128128
expect(snapshotDiff(a, b, {colors: true})).toMatchSnapshot();
129129
});
130130

131+
test('can use contextLines on diff', () => {
132+
expect(snapshotDiff(a, b, {contextLines: 0})).toMatchSnapshot();
133+
});
134+
131135
test('diffs short strings', () => {
132136
const x = `
133137
abcx

‎src/index.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ const reactElement = Symbol.for('react.element');
88

99
type Options = {
1010
expand?: boolean,
11-
colors?: boolean
11+
colors?: boolean,
12+
contextLines?: number,
1213
};
1314

1415
const defaultOptions = {
1516
expand: false,
16-
colors: false
17+
colors: false,
18+
contextLines: -1, // Forces to use default from Jest
1719
};
1820

1921
const snapshotDiff = (
@@ -42,6 +44,7 @@ const isReactComponent = valueA => valueA && valueA.$$typeof === reactElement;
4244
function diffStrings(valueA, valueB, options) {
4345
return diff(valueA, valueB, {
4446
expand: options.expand,
47+
contextLines: options.contextLines,
4548
aAnnotation: 'First value',
4649
bAnnotation: 'Second value'
4750
});
@@ -55,6 +58,7 @@ function diffReactComponents(valueA, valueB, options) {
5558

5659
return diff(reactValueA, reactValueB, {
5760
expand: options.expand,
61+
contextLines: options.contextLines,
5862
aAnnotation: prettyFormat(valueA, prettyFormatOptions),
5963
bAnnotation: prettyFormat(valueB, prettyFormatOptions)
6064
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /