Skip to content

Commit

Permalink
Present diffs for mismatched actual and expected JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha authored and ariya committed Dec 14, 2013
1 parent 39894c1 commit f462636
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
coverage
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -30,7 +30,8 @@
"istanbul": "~0.1.27", "istanbul": "~0.1.27",
"complexity-report": "~0.6.1", "complexity-report": "~0.6.1",
"regenerate": "~0.5.4", "regenerate": "~0.5.4",
"unicode-6.3.0": "~0.1.0" "unicode-6.3.0": "~0.1.0",
"json-diff": "~0.3.1"
}, },
"keywords": [ "keywords": [
"ast", "ast",
Expand Down
17 changes: 14 additions & 3 deletions test/runner.js
Expand Up @@ -417,6 +417,7 @@ if (typeof window !== 'undefined') {
var esprima = require('../esprima'), var esprima = require('../esprima'),
vm = require('vm'), vm = require('vm'),
fs = require('fs'), fs = require('fs'),
diff = require('json-diff').diffString,
total = 0, total = 0,
failures = [], failures = [],
tick = new Date(), tick = new Date(),
Expand Down Expand Up @@ -444,9 +445,19 @@ if (typeof window !== 'undefined') {
if (failures.length) { if (failures.length) {
console.error(header); console.error(header);
failures.forEach(function (failure) { failures.forEach(function (failure) {
console.error(failure.source + ': Expected\n ' + try {
failure.expected.split('\n').join('\n ') + var expectedObject = JSON.parse(failure.expected);
'\nto match\n ' + failure.actual); var actualObject = JSON.parse(failure.actual);

console.error(failure.source + ': Expected\n ' +
failure.expected.split('\n').join('\n ') +
'\nto match\n ' + failure.actual + '\nDiff:\n' +
diff(expectedObject, actualObject));
} catch (ex) {
console.error(failure.source + ': Expected\n ' +
failure.expected.split('\n').join('\n ') +
'\nto match\n ' + failure.actual);
}
}); });
} else { } else {
console.log(header); console.log(header);
Expand Down

0 comments on commit f462636

Please sign in to comment.