Skip to content
Browse files

Present diffs for mismatched actual and expected JSON.

  • Loading branch information...
1 parent 39894c1 commit f4626369060156352ea41c75391d20d6a9905cc2 @eventualbuddha eventualbuddha committed with Dec 11, 2013
Showing with 17 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 package.json
  3. +14 −3 test/runner.js
View
1 .gitignore
@@ -0,0 +1 @@
+coverage
View
3 package.json
@@ -30,7 +30,8 @@
"istanbul": "~0.1.27",
"complexity-report": "~0.6.1",
"regenerate": "~0.5.4",
- "unicode-6.3.0": "~0.1.0"
+ "unicode-6.3.0": "~0.1.0",
+ "json-diff": "~0.3.1"
},
"keywords": [
"ast",
View
17 test/runner.js
@@ -417,6 +417,7 @@ if (typeof window !== 'undefined') {
var esprima = require('../esprima'),
vm = require('vm'),
fs = require('fs'),
+ diff = require('json-diff').diffString,
total = 0,
failures = [],
tick = new Date(),
@@ -444,9 +445,19 @@ if (typeof window !== 'undefined') {
if (failures.length) {
console.error(header);
failures.forEach(function (failure) {
- console.error(failure.source + ': Expected\n ' +
- failure.expected.split('\n').join('\n ') +
- '\nto match\n ' + failure.actual);
+ try {
+ var expectedObject = JSON.parse(failure.expected);
+ 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 {
console.log(header);

0 comments on commit f462636

Please sign in to comment.
Something went wrong with that request. Please try again.