Skip to content

Commit

Permalink
use json-stringify-safe in render.js to not throw on circular structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Mar 21, 2013
1 parent 35ba8a3 commit 51a4e66
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/render.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Stream = require('stream');
var json = typeof JSON === 'object' ? JSON : require('jsonify');
var getSerialize = require('json-stringify-safe').getSerialize()

module.exports = Render;

Expand Down Expand Up @@ -70,8 +71,8 @@ function encodeResult (res, count) {
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';

var ex = json.stringify(res.expected) || '';
var ac = json.stringify(res.actual) || '';
var ex = json.stringify(res.expected, getSerialize) || '';
var ac = json.stringify(res.actual, getSerialize) || '';

if (Math.max(ex.length, ac.length) > 65) {
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"dependencies" : {
"jsonify" : "~0.0.0",
"deep-equal" : "~0.0.0",
"defined" : "~0.0.0"
"defined" : "~0.0.0",
"json-stringify-safe": "~4.0.0"
},
"devDependencies" : {
"tap" : "~0.3.0",
Expand Down
43 changes: 43 additions & 0 deletions test/circular-things.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var tape = require('../');
var tap = require('tap');

tap.test('circular test', function (assert) {
var test = tape.createHarness({ exit : false });
var tc = tap.createConsumer();

var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
// console.log("rs", rows)

// console.log("deepEqual?")

assert.same(rows, [
"TAP version 13"
, "circular"
, { id: 1
, ok: false
, name: " should be equal"
, operator: "equal"
, expected: "{}"
, actual: '{"circular":"[Circular]"}'
}
, "tests 1"
, "pass 0"
, "fail 1"
])
assert.end()
})

// tt.equal(10, 10)
// tt.end()

test.stream.pipe(tc);

test("circular", function (t) {
t.plan(1)
var circular = {}
circular.circular = circular
t.equal(circular, {})
})
})

0 comments on commit 51a4e66

Please sign in to comment.