strip comments unit test

This commit is contained in:
fewieden 2018-02-13 07:17:46 +01:00
parent d775bc9d7e
commit d709a44960
3 changed files with 74 additions and 41 deletions

View File

@ -0,0 +1,13 @@
{
// Escaped
"FOO\"BAR": "Today",
/*
* The following lines
* represent cardinal directions
*/
"N": "N",
"E": "E",
"S": "S",
"W": "W"
}

View File

@ -2,6 +2,7 @@ const chai = require("chai");
const expect = chai.expect;
const path = require("path");
const fs = require("fs");
const helmet = require("helmet");
const {JSDOM} = require("jsdom");
const express = require("express");
@ -10,12 +11,12 @@ describe("Translator", function() {
before(function() {
const app = express();
app.get("/translations/:file", function(req, res) {
res.status(200)
.header("Access-Control-Allow-Origin", "*")
.json(require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", req.params.file)));
app.use(helmet());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.use("/translations", express.static(path.join(__dirname, "..", "..", "..", "tests", "configs", "data")));
server = app.listen(3000);
});
@ -180,6 +181,26 @@ describe("Translator", function() {
};
});
it("should strip comments", function(done) {
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
resources: "usable" });
dom.window.onload = function() {
const {Translator} = dom.window;
const file = "StripComments.json";
Translator.load(mmm, file, false, function() {
expect(Translator.translations[mmm.name]).to.be.deep.equal({
"FOO\"BAR": "Today",
"N": "N",
"E": "E",
"S": "S",
"W": "W"
});
done();
});
};
});
it("should not load translations, if module fallback exists", function(done) {
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
resources: "usable" });
@ -267,7 +288,6 @@ describe("Translator", function() {
const {Translator} = dom.window;
Translator.loadCoreTranslations();
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function() {
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
done();