Skip to content

Commit 99b8851

Browse files
authored
Merge 9af7696 into 0ef5e52
2 parents 0ef5e52 + 9af7696 commit 99b8851

File tree

7 files changed

+341
-163
lines changed

7 files changed

+341
-163
lines changed

index.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,37 @@ function lpad (str, width) {
265265
}
266266

267267
/**
268-
* Wrap string with ANSI sequence for red.
269-
*
270-
* @param {string} str String to wrap
271-
* @return {string}
268+
* Compose (B combinator).
272269
*/
273-
function red (str) {
274-
return '\x1B[31m' + str + '\x1B[0m'
270+
function B (f, g) {
271+
return function (x) {
272+
return f(g(x))
273+
}
275274
}
276275

277276
/**
278-
* Wrap string with ANSI sequence for green.
277+
* Create a colorize function.
279278
*
280-
* @param {string} str String to wrap
281-
* @return {string}
279+
* @param {number} code ANSI color code
280+
* @return {function}
282281
*/
283-
function green (str) {
284-
return '\x1B[32m' + str + '\x1B[0m'
282+
function color (code) {
283+
/**
284+
* Wrap string with ANSI sequence for given color code.
285+
*
286+
* @param {string} str String to wrap
287+
* @return {string}
288+
*/
289+
return function (str) {
290+
return '\x1B[' + code + 'm' + str + '\x1B[0m'
291+
}
285292
}
286293

294+
var red = color(31)
295+
var green = color(32)
296+
var redBg = B(color(41), color(37))
297+
var greenBg = B(color(42), color(30))
298+
287299
/**
288300
* Identity function.
289301
*
@@ -389,8 +401,8 @@ module.exports = function jasmineDiffMatchers (j$, options) {
389401
inline: options && options.inline === true,
390402
spaces: 2
391403
}
392-
var annotateAdd = opts.colors ? green : identity
393-
var annotateRemove = opts.colors ? red : identity
404+
var annotateAdd = opts.colors ? (opts.inline ? greenBg : green) : identity
405+
var annotateRemove = opts.colors ? (opts.inline ? redBg : red) : identity
394406
var errorDiff = opts.inline ? inlineDiff : unifiedDiff
395407
var stringify = createStringifier(j$.pp, opts.spaces)
396408

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
"test:unit": "nyc tape test/unit/*.test.js",
1818
"test:functional": "tape test/functional",
1919
"test": "npm run test:unit && npm run test:functional",
20-
"validate": "npm test && npm run coveralls"
20+
"validate": "npm test && npm run coveralls",
21+
"update-fixture1": "karma start test/functional/karma.conf.js > test/functional/fixtures/karma.conf.js.output || exit 0",
22+
"update-fixture2": "karma start test/functional/karma.conf.inline.js > test/functional/fixtures/karma.conf.inline.js.output || exit 0",
23+
"update-fixture3": "karma start test/functional/karma.conf.colors.js > test/functional/fixtures/karma.conf.colors.js.output || exit 0",
24+
"update-fixtures": "npm run update-fixture1 && npm run update-fixture2 && npm run update-fixture3"
2125
},
2226
"homepage": "https://github.com/jimf/jasmine-diff",
2327
"repository": {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show diff with colors FAILED
2+
Expected object to have properties
3+
baz: 'baz'
4+
Expected object not to have properties
5+
bar: 'bar'
6+
7+
+ expected
8+
- actual
9+
10+
- 'bar': 'bar'
11+
+ 'baz': 'baz'
12+
13+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure_colored.js:12:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/d2ab8711400d415d82fff1b0b8ee14d1.browserify:2291:49
14+
loaded@http://localhost:9876/context.js:162:17
15+
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.009 secs / 0.007 secs)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show inline diff with colors FAILED
2+
Expected $.bar = 'bar' to equal 'baz'.
3+
4+
actual expected
5+
6+
{
7+
'bar': 'barbaz'
8+
'foo': 'foo'
9+
}
10+
11+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure_inline.js:12:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/ed2f426bd5eee6ce9d7ff9abaeb0afe6.browserify:2291:49
12+
loaded@http://localhost:9876/context.js:162:17
13+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should include line numbers when diff exceeds 4 lines FAILED
14+
Expected $.baz = 'qux' to equal 'baz'.
15+
16+
actual expected
17+
18+
1 | {
19+
2 | 'bar': 'bar'
20+
3 | 'baz': 'quxbaz'
21+
4 | 'foo': 'foo'
22+
5 | }
23+
24+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure_inline.js:16:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/ed2f426bd5eee6ce9d7ff9abaeb0afe6.browserify:2295:61
25+
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 2 of 2 (2 FAILED) ERROR (0.011 secs / 0.007 secs)
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should omit diff when comparing null/undefined FAILED
2+
Expected null to be undefined.
3+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:12:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2291:24
4+
loaded@http://localhost:9876/context.js:162:17
5+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should omit diff when comparing scalars FAILED
6+
Expected 42 to be true.
7+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:15:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2294:22
8+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should show diff when comparing long strings FAILED
9+
Expected 'The quick brown fox jumped over the lazy dog' to be 'The quick black cat hissed at the lazy dog'.
10+
11+
+ expected
12+
- actual
13+
14+
-The quick brown fox jumped over the lazy dog
15+
+The quick black cat hissed at the lazy dog
16+
17+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:18:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2297:66
18+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should show diff when comparing multiline strings FAILED
19+
Expected 'The quick brown fox
20+
jumped over the lazy dog' to be 'The quick black cat
21+
hissed at the lazy dog'.
22+
23+
+ expected
24+
- actual
25+
26+
-The quick brown fox
27+
-jumped over the lazy dog
28+
+The quick black cat
29+
+hissed at the lazy dog
30+
31+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:23:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2302:67
32+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should show diff when comparing arrays FAILED
33+
Expected [ 1, 2, 3 ] to be [ 1, 2, 3, 4 ].
34+
35+
+ expected
36+
- actual
37+
38+
+ 4
39+
40+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:28:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2307:29
41+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should show diff when comparing objects FAILED
42+
Expected Object({ foo: 'foo', bar: 'bar' }) to be Object({ foo: 'foo', baz: 'baz' }).
43+
44+
+ expected
45+
- actual
46+
47+
- 'bar': 'bar'
48+
+ 'baz': 'baz'
49+
50+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:31:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2310:46
51+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toBe should format values FAILED
52+
Expected Object({ }) to be Object({ a: null, b: undefined, c: 1, d: -1, e: 'a', f: Function, g: /[aeiou]/, h: [ ], i: [ 1, 2, 3 ], j: [ [ 1 ], [ 2, 3 ] ], k: Object({ }), l: Object({ a: 1, b: 2, c: 3 }), m: Object({ a: Object({ b: Object({ c: 1 }) }) }), n: Object({ a: [ Object({ b: true }) ] }) }).
53+
54+
+ expected
55+
- actual
56+
57+
-{}
58+
+{
59+
+ 'a': null
60+
+ 'b': undefined
61+
+ 'c': 1
62+
+ 'd': -1
63+
+ 'e': 'a'
64+
+ 'f': Function
65+
+ 'g': /[aeiou]/
66+
+ 'h': []
67+
+ 'i': [
68+
+ 1
69+
+ 2
70+
+ 3
71+
+ ]
72+
+ 'j': [
73+
+ [
74+
+ 1
75+
+ ]
76+
+ [
77+
+ 2
78+
+ 3
79+
+ ]
80+
+ ]
81+
+ 'k': {}
82+
+ 'l': {
83+
+ 'a': 1
84+
+ 'b': 2
85+
+ 'c': 3
86+
+ }
87+
+ 'm': {
88+
+ 'a': {
89+
+ 'b': {
90+
+ 'c': 1
91+
+ }
92+
+ }
93+
+ }
94+
+ 'n': {
95+
+ 'a': [
96+
+ {
97+
+ 'b': true
98+
+ }
99+
+ ]
100+
+ }
101+
+}
102+
103+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:51:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2330:26
104+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toBe should omit diff when comparing null/undefined FAILED
105+
Expected null not to be null.
106+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:57:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2336:28
107+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toBe should omit diff when comparing scalars FAILED
108+
Expected 42 not to be 42.
109+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:60:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2339:26
110+
..
111+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should omit diff when comparing null/undefined FAILED
112+
Expected null to equal undefined.
113+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:72:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2351:27
114+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should omit diff when comparing scalars FAILED
115+
Expected 42 to equal true.
116+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:75:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2354:25
117+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show diff when comparing long strings FAILED
118+
Expected 'The quick brown fox jumped over the lazy dog' to equal 'The quick black cat hissed at the lazy dog'.
119+
120+
+ expected
121+
- actual
122+
123+
-The quick brown fox jumped over the lazy dog
124+
+The quick black cat hissed at the lazy dog
125+
126+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:78:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2357:69
127+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show diff when comparing multiline strings FAILED
128+
Expected 'The quick brown fox
129+
jumped over the lazy dog' to equal 'The quick black cat
130+
hissed at the lazy dog'.
131+
132+
+ expected
133+
- actual
134+
135+
-The quick brown fox
136+
-jumped over the lazy dog
137+
+The quick black cat
138+
+hissed at the lazy dog
139+
140+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:83:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2362:70
141+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show diff when comparing arrays FAILED
142+
Expected $.length = 3 to equal 4.
143+
Expected $[3] = undefined to equal 4.
144+
145+
+ expected
146+
- actual
147+
148+
+ 4
149+
150+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:88:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2367:32
151+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should show diff when comparing objects FAILED
152+
Expected object to have properties
153+
baz: 'baz'
154+
Expected object not to have properties
155+
bar: 'bar'
156+
157+
+ expected
158+
- actual
159+
160+
- 'bar': 'bar'
161+
+ 'baz': 'baz'
162+
163+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:91:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2370:49
164+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers toEqual should format values FAILED
165+
Expected object to have properties
166+
a: null
167+
b: undefined
168+
c: 1
169+
d: -1
170+
e: 'a'
171+
f: Function
172+
g: /[aeiou]/
173+
h: [ ]
174+
i: [ 1, 2, 3 ]
175+
j: [ [ 1 ], [ 2, 3 ] ]
176+
k: Object({ })
177+
l: Object({ a: 1, b: 2, c: 3 })
178+
m: Object({ a: Object({ b: Object({ c: 1 }) }) })
179+
n: Object({ a: [ Object({ b: true }) ] })
180+
181+
+ expected
182+
- actual
183+
184+
-{}
185+
+{
186+
+ 'a': null
187+
+ 'b': undefined
188+
+ 'c': 1
189+
+ 'd': -1
190+
+ 'e': 'a'
191+
+ 'f': Function
192+
+ 'g': /[aeiou]/
193+
+ 'h': []
194+
+ 'i': [
195+
+ 1
196+
+ 2
197+
+ 3
198+
+ ]
199+
+ 'j': [
200+
+ [
201+
+ 1
202+
+ ]
203+
+ [
204+
+ 2
205+
+ 3
206+
+ ]
207+
+ ]
208+
+ 'k': {}
209+
+ 'l': {
210+
+ 'a': 1
211+
+ 'b': 2
212+
+ 'c': 3
213+
+ }
214+
+ 'm': {
215+
+ 'a': {
216+
+ 'b': {
217+
+ 'c': 1
218+
+ }
219+
+ }
220+
+ }
221+
+ 'n': {
222+
+ 'a': [
223+
+ {
224+
+ 'b': true
225+
+ }
226+
+ ]
227+
+ }
228+
+}
229+
230+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:111:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2390:29
231+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toEqual should omit diff when comparing null/undefined FAILED
232+
Expected null not to equal null.
233+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:117:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2396:31
234+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toEqual should omit diff when comparing scalars FAILED
235+
Expected 42 not to equal 42.
236+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:120:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2399:29
237+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toEqual should show diff when comparing arrays FAILED
238+
Expected [ 1, 2, 3 ] not to equal [ 1, 2, 3 ].
239+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:123:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2402:36
240+
PhantomJS 2.1.1 (Mac OS X 0.0.0) Jasmine Diff Matchers not.toEqual should show diff when comparing objects FAILED
241+
Expected Object({ foo: 'foo', bar: 'bar' }) not to equal Object({ foo: 'foo', bar: 'bar' }).
242+
/var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/failure.js:126:0 <- /var/folders/x3/t7h_ctrn0151f51k6nsvtcl40001z4/T/89e0464e73cdbed3366e80b1656c159b.browserify:2405:53
243+
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 22 of 22 (20 FAILED) (0.033 secs / 0.02 secs)

0 commit comments

Comments
 (0)