Skip to content

Commit

Permalink
using object-inspect for comparisons, passing the undef test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Mar 5, 2014
1 parent 9ee8421 commit 49963b3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 78 deletions.
27 changes: 3 additions & 24 deletions lib/results.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var EventEmitter = require('events').EventEmitter;
var inherits = require('inherits');
var json = typeof JSON === 'object' ? JSON : require('jsonify');
var through = require('through');
var resumer = require('resumer');
var inspect = require('object-inspect');
var nextTick = typeof setImmediate !== 'undefined'
? setImmediate
: process.nextTick
Expand Down Expand Up @@ -141,8 +141,8 @@ function encodeResult (res, count) {
output += outer + '---\n';
output += inner + 'operator: ' + res.operator + '\n';

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

if (Math.max(ex.length, ac.length) > 65) {
output += inner + 'expected:\n' + inner + ' ' + ex + '\n';
Expand All @@ -168,27 +168,6 @@ function encodeResult (res, count) {
return output;
}

function getSerialize () {
var seen = [];

return function (key, value) {
var ret = value;
if (typeof value === 'object' && value) {
var found = false;
for (var i = 0; i < seen.length; i++) {
if (seen[i] === value) {
found = true
break;
}
}

if (found) ret = '[Circular]'
else seen.push(value)
}
return ret;
};
}

function getNextTest (results) {
if (!results._only) {
return results.tests.shift();
Expand Down
108 changes: 55 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
{
"name" : "tape",
"version" : "2.6.0",
"description" : "tap-producing test harness for node and browsers",
"main" : "index.js",
"bin" : "./bin/tape",
"directories" : {
"example" : "example",
"test" : "test"
},
"dependencies" : {
"jsonify" : "~0.0.0",
"deep-equal" : "~0.2.0",
"defined" : "~0.0.0",
"through": "~2.3.4",
"resumer": "~0.0.0",
"inherits": "~2.0.1"
},
"devDependencies" : {
"tap" : "~0.3.0",
"falafel" : "~0.1.4"
},
"scripts" : {
"test" : "tap test/*.js"
},
"testling" : {
"files" : "test/browser/*.js",
"browsers" : [
"ie/6..latest",
"chrome/20..latest",
"firefox/10..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6", "ipad/6"
]
},
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/tape.git"
},
"homepage" : "https://github.com/substack/tape",
"keywords" : [
"tap",
"test",
"harness",
"assert",
"browser"
],
"author" : {
"name" : "James Halliday",
"email" : "[email protected]",
"url" : "http://substack.net"
},
"license" : "MIT"
"name": "tape",
"version": "2.6.0",
"description": "tap-producing test harness for node and browsers",
"main": "index.js",
"bin": "./bin/tape",
"directories": {
"example": "example",
"test": "test"
},
"dependencies": {
"deep-equal": "~0.2.0",
"defined": "~0.0.0",
"inherits": "~2.0.1",
"object-inspect": "~0.3.0",
"resumer": "~0.0.0",
"through": "~2.3.4"
},
"devDependencies": {
"tap": "~0.3.0",
"concat": "~1.4.1",
"falafel": "~0.1.4"
},
"scripts": {
"test": "tap test/*.js"
},
"testling": {
"files": "test/browser/*.js",
"browsers": [
"ie/6..latest",
"chrome/20..latest",
"firefox/10..latest",
"safari/latest",
"opera/11.0..latest",
"iphone/6",
"ipad/6"
]
},
"repository": {
"type": "git",
"url": "git://github.com/substack/tape.git"
},
"homepage": "https://github.com/substack/tape",
"keywords": [
"tap",
"test",
"harness",
"assert",
"browser"
],
"author": {
"name": "James Halliday",
"email": "[email protected]",
"url": "http://substack.net"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion test/circular-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tap.test('circular test', function (assert) {
, name: " should be equal"
, operator: "equal"
, expected: "{}"
, actual: '{"circular":"[Circular]"}'
, actual: '{ circular: [Circular] }'
}
, "tests 1"
, "pass 0"
Expand Down

0 comments on commit 49963b3

Please sign in to comment.