Split translation key testing

All keys in a translation file should be in the base file (en.json).
When there are keys in the base file that are not in a translation,
the translation file test is skipped.
This commit is contained in:
Chris van Marle 2017-02-03 10:10:03 +01:00
parent 406ae4e8c3
commit d004c0ccd1

View File

@ -3,9 +3,6 @@ var path = require("path");
var chai = require("chai"); var chai = require("chai");
var expect = chai.expect; var expect = chai.expect;
// Disabled for now, because of too many errors
// Remove .skip from it to enable
describe("Translations have the same keys as en.js", function() { describe("Translations have the same keys as en.js", function() {
var translations = require("../../../translations/translations.js"); var translations = require("../../../translations/translations.js");
var base = JSON.parse(stripComments(fs.readFileSync("translations/en.json", "utf8"))); var base = JSON.parse(stripComments(fs.readFileSync("translations/en.json", "utf8")));
@ -13,24 +10,33 @@ describe("Translations have the same keys as en.js", function() {
Object.keys(translations).forEach(function(tr) { Object.keys(translations).forEach(function(tr) {
var fileName = translations[tr]; var fileName = translations[tr];
it(fileName + " should match", function() { var fileContent = stripComments(fs.readFileSync(fileName, "utf8"));
var fileContent = stripComments(fs.readFileSync(fileName, "utf8")); var fileTranslations = JSON.parse(fileContent);
var fileTranslations = JSON.parse(fileContent); var fileKeys = Object.keys(fileTranslations).sort();
var fileKeys = Object.keys(fileTranslations).sort();
// TODO: when all translations are fixed, use it(fileName + " keys should be in base", function() {
// expect(fileKeys).to.deep.equal(baseKeys); fileKeys.forEach(function(key) {
expect( baseKeys.indexOf(key) ).to.be.at.least(0);
});
});
// Then delete this block: it(fileName + " should contain all base keys", function() {
try { var test = this;
expect(fileKeys).to.deep.equal(baseKeys); baseKeys.forEach(function(key) {
} catch(e) { // TODO: when all translations are fixed, use
if (e instanceof chai.AssertionError) { // expect(fileKeys).to.deep.equal(baseKeys);
this.skip(); // instead of the try-catch-block
} else {
throw e; try {
expect(fileKeys).to.deep.equal(baseKeys);
} catch(e) {
if (e instanceof chai.AssertionError) {
test.skip();
} else {
throw e;
}
} }
} });
}); });
}); });
}); });