Last active
August 29, 2015 14:25
-
-
Save willscripted/a8ad8f65f8c0d061f7a7 to your computer and use it in GitHub Desktop.
compare json via named pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect = require('chai').expect | |
diff = require('diff') | |
require('colors').enabled = true; | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('readable', function(){ | |
var chunk = process.stdin.read(); | |
if (chunk !== null) { | |
try { | |
json = JSON.parse(chunk); | |
expect(json[0]).to.deep.eql(json[1]); | |
process.stdout.write("Success\n"); | |
} catch(err) { | |
var parts = diff.diffJson(err.actual,err.expected) | |
parts.forEach(function(part){ | |
var color = part.added ? 'green' : | |
part.removed ? 'red' : 'grey'; | |
process.stdout.write(part.value[color]); | |
}); | |
process.stdout.write("\nError: " + err + "\n"); | |
} | |
} | |
}); | |
process.stdin.on('end', function(){ | |
process.stdout.write('end'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "comp", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"chai": "^3.1.0", | |
"colors": "^1.1.2", | |
"diff": "^1.4.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment