scratch-www/test/localization/check_valid_json.js
chrisgarrity 376aee0eb3 Add error checking and testing for translations (#1401)
* Add error checking and testing for translations. Also make build-locales quieter if there are no problems.

* Allow build with broken translations (to allow development), but fail test so that broken translations don't get merged or deployed
2017-08-15 09:32:18 -04:00

27 lines
629 B
JavaScript

var fs = require('fs');
var glob = require('glob');
var tap = require('tap');
var TRANSLATIONS_PATTERN = './node_modules/scratchr2_translations/www/**/*.json';
var files = glob.sync(TRANSLATIONS_PATTERN);
function checkJson (data, name) {
try {
JSON.parse(data);
} catch (e) {
tap.fail(name + ' has invalid Json.\n');
}
tap.pass();
}
files.forEach(function (f) {
tap.test('check valid json', function (t) {
fs.readFile(f, function (err, data) {
if (err) {
throw err;
}
checkJson(data, f);
});
t.end();
});
});