mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
linting
This commit is contained in:
@@ -9,121 +9,121 @@ const {JSDOM} = require("jsdom");
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
|
||||||
describe("Translations", function() {
|
describe("Translations", function() {
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
app.use("/translations", express.static(path.join(__dirname, "..", "..", "translations")));
|
app.use("/translations", express.static(path.join(__dirname, "..", "..", "translations")));
|
||||||
|
|
||||||
server = app.listen(3000);
|
server = app.listen(3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should have a translation file in the specified path", function() {
|
it("should have a translation file in the specified path", function() {
|
||||||
for(let language in translations) {
|
for(let language in translations) {
|
||||||
const file = fs.statSync(translations[language]);
|
const file = fs.statSync(translations[language]);
|
||||||
expect(file.isFile()).to.be.equal(true);
|
expect(file.isFile()).to.be.equal(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const mmm = {
|
const mmm = {
|
||||||
name: "TranslationTest",
|
name: "TranslationTest",
|
||||||
file(file) {
|
file(file) {
|
||||||
return `http://localhost:3000/${file}`;
|
return `http://localhost:3000/${file}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("Parsing language files through the Translator class", function() {
|
describe("Parsing language files through the Translator class", function() {
|
||||||
for(let language in translations) {
|
for(let language in translations) {
|
||||||
it(`should parse ${language}`, function(done) {
|
it(`should parse ${language}`, function(done) {
|
||||||
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||||
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
dom.window.onload = function() {
|
dom.window.onload = function() {
|
||||||
const {Translator} = dom.window;
|
const {Translator} = dom.window;
|
||||||
|
|
||||||
Translator.load(mmm, translations[language], false, function() {
|
Translator.load(mmm, translations[language], false, function() {
|
||||||
expect(Translator.translations[mmm.name]).to.be.an('object');
|
expect(Translator.translations[mmm.name]).to.be.an("object");
|
||||||
expect(Object.keys(Translator.translations[mmm.name]).length).to.be.at.least(1);
|
expect(Object.keys(Translator.translations[mmm.name]).length).to.be.at.least(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Same keys", function() {
|
describe("Same keys", function() {
|
||||||
let base;
|
let base;
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||||
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
dom.window.onload = function() {
|
dom.window.onload = function() {
|
||||||
const {Translator} = dom.window;
|
const {Translator} = dom.window;
|
||||||
|
|
||||||
Translator.load(mmm, translations.en, false, function() {
|
Translator.load(mmm, translations.en, false, function() {
|
||||||
base = Object.keys(Translator.translations[mmm.name]).sort();
|
base = Object.keys(Translator.translations[mmm.name]).sort();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let language in translations) {
|
for (let language in translations) {
|
||||||
if (language === "en") {
|
if (language === "en") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe(`Translation keys of ${language}`, function() {
|
describe(`Translation keys of ${language}`, function() {
|
||||||
let keys;
|
let keys;
|
||||||
|
|
||||||
before(function(done){
|
before(function(done){
|
||||||
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
const dom = new JSDOM(`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||||
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
<script src="${path.join(__dirname, "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
dom.window.onload = function() {
|
dom.window.onload = function() {
|
||||||
const {Translator} = dom.window;
|
const {Translator} = dom.window;
|
||||||
|
|
||||||
Translator.load(mmm, translations[language], false, function() {
|
Translator.load(mmm, translations[language], false, function() {
|
||||||
keys = Object.keys(Translator.translations[mmm.name]).sort();
|
keys = Object.keys(Translator.translations[mmm.name]).sort();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`${language} keys should be in base`, function() {
|
it(`${language} keys should be in base`, function() {
|
||||||
keys.forEach(function(key) {
|
keys.forEach(function(key) {
|
||||||
expect(base.indexOf(key)).to.be.at.least(0);
|
expect(base.indexOf(key)).to.be.at.least(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`${language} should contain all base keys`, function() {
|
it(`${language} should contain all base keys`, function() {
|
||||||
// TODO: when all translations are fixed, use
|
// TODO: when all translations are fixed, use
|
||||||
// expect(keys).to.deep.equal(base);
|
// expect(keys).to.deep.equal(base);
|
||||||
// instead of the try-catch-block
|
// instead of the try-catch-block
|
||||||
|
|
||||||
try {
|
try {
|
||||||
expect(keys).to.deep.equal(base);
|
expect(keys).to.deep.equal(base);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e instanceof chai.AssertionError) {
|
if (e instanceof chai.AssertionError) {
|
||||||
const diff = base.filter(key => !keys.includes(key));
|
const diff = base.filter(key => !keys.includes(key));
|
||||||
mlog.pending(`Missing Translations for language ${language}: ${diff}`);
|
mlog.pending(`Missing Translations for language ${language}: ${diff}`);
|
||||||
this.skip();
|
this.skip();
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -5,41 +5,41 @@ const {JSDOM} = require("jsdom");
|
|||||||
|
|
||||||
describe("File js/class", function() {
|
describe("File js/class", function() {
|
||||||
describe("Test function cloneObject", function() {
|
describe("Test function cloneObject", function() {
|
||||||
let clone;
|
let clone;
|
||||||
|
|
||||||
before(function(done) {
|
before(function(done) {
|
||||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`, { runScripts: "dangerously",
|
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
dom.window.onload = function() {
|
dom.window.onload = function() {
|
||||||
const {cloneObject} = dom.window;
|
const {cloneObject} = dom.window;
|
||||||
clone = cloneObject;
|
clone = cloneObject;
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be return equals object", function() {
|
it("should be return equals object", function() {
|
||||||
const expected = {name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror"};
|
const expected = {name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror"};
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj = clone(expected);
|
obj = clone(expected);
|
||||||
expect(expected).to.deep.equal(obj);
|
expect(expected).to.deep.equal(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be return equals int", function() {
|
it("should be return equals int", function() {
|
||||||
const expected = 1;
|
const expected = 1;
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj = clone(expected);
|
obj = clone(expected);
|
||||||
expect(expected).to.equal(obj);
|
expect(expected).to.equal(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be return equals string", function() {
|
it("should be return equals string", function() {
|
||||||
const expected = "Perfect stranger";
|
const expected = "Perfect stranger";
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj = clone(expected);
|
obj = clone(expected);
|
||||||
expect(expected).to.equal(obj);
|
expect(expected).to.equal(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should be return equals undefined", function() {
|
it("should be return equals undefined", function() {
|
||||||
const expected = undefined;
|
const expected = undefined;
|
||||||
let obj = {};
|
let obj = {};
|
||||||
obj = clone(expected);
|
obj = clone(expected);
|
||||||
expect(undefined).to.equal(obj);
|
expect(undefined).to.equal(obj);
|
||||||
|
Reference in New Issue
Block a user