File tree 2 files changed +28
-5
lines changed
2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 1
1
var Stream = require ( 'stream' ) ;
2
2
var json = typeof JSON === 'object' ? JSON : require ( 'jsonify' ) ;
3
- var getSerialize = require ( 'json-stringify-safe' ) . getSerialize ( )
4
3
5
4
module . exports = Render ;
6
5
@@ -71,8 +70,8 @@ function encodeResult (res, count) {
71
70
output += outer + '---\n' ;
72
71
output += inner + 'operator: ' + res . operator + '\n' ;
73
72
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 ( ) ) || '' ;
76
75
77
76
if ( Math . max ( ex . length , ac . length ) > 65 ) {
78
77
output += inner + 'expected:\n' + inner + ' ' + ex + '\n' ;
@@ -99,3 +98,28 @@ function encodeResult (res, count) {
99
98
100
99
return output ;
101
100
}
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 11
11
"dependencies" : {
12
12
"jsonify" : " ~0.0.0" ,
13
13
"deep-equal" : " ~0.0.0" ,
14
- "defined" : " ~0.0.0" ,
15
- "json-stringify-safe" : " ~4.0.0"
14
+ "defined" : " ~0.0.0"
16
15
},
17
16
"devDependencies" : {
18
17
"tap" : " ~0.3.0" ,
You can’t perform that action at this time.
0 commit comments