File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 11var Stream = require ( 'stream' ) ;
22var json = typeof JSON === 'object' ? JSON : require ( 'jsonify' ) ;
3- var getSerialize = require ( 'json-stringify-safe' ) . getSerialize ( )
43
54module . exports = Render ;
65
@@ -71,8 +70,8 @@ function encodeResult (res, count) {
7170 output += outer + '---\n' ;
7271 output += inner + 'operator: ' + res . operator + '\n' ;
7372
74- var ex = json . stringify ( res . expected , getSerialize ) || '' ;
75- var ac = json . stringify ( res . actual , getSerialize ) || '' ;
73+ var ex = json . stringify ( res . expected , getSerialize ( ) ) || '' ;
74+ var ac = json . stringify ( res . actual , getSerialize ( ) ) || '' ;
7675
7776 if ( Math . max ( ex . length , ac . length ) > 65 ) {
7877 output += inner + 'expected:\n' + inner + ' ' + ex + '\n' ;
@@ -99,3 +98,28 @@ function encodeResult (res, count) {
9998
10099 return output ;
101100}
101+
102+ function getSerialize ( ) {
103+ var seen = [ ] ;
104+
105+ return function ( key , value ) {
106+ var ret = value ;
107+ if ( typeof value === 'object' && value ) {
108+ var found = false
109+ for ( var i = 0 ; i < seen . length ; i ++ ) {
110+ if ( seen [ i ] === value ) {
111+ found = true
112+ break ;
113+ }
114+ }
115+
116+ if ( found ) {
117+ ret = '[Circular]'
118+ } else {
119+ seen . push ( value )
120+ }
121+ }
122+
123+ return ret
124+ }
125+ }
Original file line number Diff line number Diff line change 1111 "dependencies" : {
1212 "jsonify" : " ~0.0.0" ,
1313 "deep-equal" : " ~0.0.0" ,
14- "defined" : " ~0.0.0" ,
15- "json-stringify-safe" : " ~4.0.0"
14+ "defined" : " ~0.0.0"
1615 },
1716 "devDependencies" : {
1817 "tap" : " ~0.3.0" ,
You can’t perform that action at this time.
0 commit comments