Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created January 14, 2016 01:00
Show Gist options
  • Save tmcw/07e6ea91ed1ac43aa7db to your computer and use it in GitHub Desktop.
Save tmcw/07e6ea91ed1ac43aa7db to your computer and use it in GitHub Desktop.
var remark = require('remark');
var expect = require('expect');
var fs = require('fs');
var visit = require('unist-util-visit');
describe('json validity', () => {
fs.readdirSync('./content').forEach(function(file) {
it('valid ' + file, function() {
var content = fs.readFileSync('./content/' + file, 'utf8');
var ast = remark.parse(content);
visit(ast, 'code', function(node) {
if (node.lang === 'json') {
expect(function() {
JSON.parse(node.value);
}).toNotThrow(null, 'a JSON code block at L:' +
node.position.start.line + ' of ' + file + ' was invalid');
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment