mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
strip comments unit test
This commit is contained in:
parent
d775bc9d7e
commit
d709a44960
13
tests/configs/data/StripComments.json
Normal file
13
tests/configs/data/StripComments.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
// Escaped
|
||||||
|
"FOO\"BAR": "Today",
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following lines
|
||||||
|
* represent cardinal directions
|
||||||
|
*/
|
||||||
|
"N": "N",
|
||||||
|
"E": "E",
|
||||||
|
"S": "S",
|
||||||
|
"W": "W"
|
||||||
|
}
|
@ -2,6 +2,7 @@ const chai = require("chai");
|
|||||||
const expect = chai.expect;
|
const expect = chai.expect;
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const helmet = require("helmet");
|
||||||
const {JSDOM} = require("jsdom");
|
const {JSDOM} = require("jsdom");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
|
||||||
@ -10,12 +11,12 @@ describe("Translator", function() {
|
|||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
const app = express();
|
const app = express();
|
||||||
|
app.use(helmet());
|
||||||
app.get("/translations/:file", function(req, res) {
|
app.use(function (req, res, next) {
|
||||||
res.status(200)
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
.header("Access-Control-Allow-Origin", "*")
|
next();
|
||||||
.json(require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", req.params.file)));
|
|
||||||
});
|
});
|
||||||
|
app.use("/translations", express.static(path.join(__dirname, "..", "..", "..", "tests", "configs", "data")));
|
||||||
|
|
||||||
server = app.listen(3000);
|
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) {
|
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",
|
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
@ -267,7 +288,6 @@ describe("Translator", function() {
|
|||||||
const {Translator} = dom.window;
|
const {Translator} = dom.window;
|
||||||
Translator.loadCoreTranslations();
|
Translator.loadCoreTranslations();
|
||||||
|
|
||||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
|
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
|
||||||
done();
|
done();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user