mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-27 16:25:21 +00:00
Run prettier over ALL files once
No other changes done in this commit
This commit is contained in:
@@ -1,38 +1,40 @@
|
||||
const expect = require("chai").expect;
|
||||
const path = require("path");
|
||||
const {JSDOM} = require("jsdom");
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
describe("File js/class", function() {
|
||||
describe("Test function cloneObject", function() {
|
||||
describe("File js/class", function () {
|
||||
describe("Test function cloneObject", function () {
|
||||
let clone;
|
||||
let dom;
|
||||
|
||||
before(function(done) {
|
||||
dom = new JSDOM(`<script>var Log = {log: function() {}};</script>\
|
||||
<script src="${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {cloneObject} = dom.window;
|
||||
before(function (done) {
|
||||
dom = new JSDOM(
|
||||
`<script>var Log = {log: function() {}};</script>\
|
||||
<script src="${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
const { cloneObject } = dom.window;
|
||||
clone = cloneObject;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should clone object", function() {
|
||||
const expected = {name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror"};
|
||||
it("should clone object", function () {
|
||||
const expected = { name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror" };
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.deep.equal(expected);
|
||||
expect(expected === obj).to.equal(false);
|
||||
});
|
||||
|
||||
it("should clone array", function() {
|
||||
it("should clone array", function () {
|
||||
const expected = [1, null, undefined, "TEST"];
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.deep.equal(expected);
|
||||
expect(expected === obj).to.equal(false);
|
||||
});
|
||||
|
||||
it("should clone number", function() {
|
||||
it("should clone number", function () {
|
||||
let expected = 1;
|
||||
let obj = clone(expected);
|
||||
expect(obj).to.equal(expected);
|
||||
@@ -42,32 +44,32 @@ describe("File js/class", function() {
|
||||
expect(obj).to.equal(expected);
|
||||
});
|
||||
|
||||
it("should clone string", function() {
|
||||
it("should clone string", function () {
|
||||
const expected = "Perfect stranger";
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.equal(expected);
|
||||
});
|
||||
|
||||
it("should clone undefined", function() {
|
||||
it("should clone undefined", function () {
|
||||
const expected = undefined;
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.equal(expected);
|
||||
});
|
||||
|
||||
it("should clone null", function() {
|
||||
it("should clone null", function () {
|
||||
const expected = null;
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.equal(expected);
|
||||
});
|
||||
|
||||
it("should clone nested object", function() {
|
||||
it("should clone nested object", function () {
|
||||
const expected = {
|
||||
name: "fewieden",
|
||||
link: "https://github.com/fewieden",
|
||||
versions: ["2.0", "2.1", "2.2"],
|
||||
answerForAllQuestions: 42,
|
||||
properties: {
|
||||
items: [{foo: "bar"}, {lorem: "ipsum"}],
|
||||
items: [{ foo: "bar" }, { lorem: "ipsum" }],
|
||||
invalid: undefined,
|
||||
nothing: null
|
||||
}
|
||||
@@ -82,22 +84,22 @@ describe("File js/class", function() {
|
||||
expect(expected.properties.items[1] === obj.properties.items[1]).to.equal(false);
|
||||
});
|
||||
|
||||
describe("Test lockstring code", function() {
|
||||
describe("Test lockstring code", function () {
|
||||
let log;
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
log = dom.window.Log.log;
|
||||
dom.window.Log.log = function cmp(str) {
|
||||
expect(str).to.equal("lockStrings");
|
||||
};
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
dom.window.Log.log = log;
|
||||
});
|
||||
|
||||
it("should clone object and log lockStrings", function() {
|
||||
const expected = {name: "Module", lockStrings: "stringLock"};
|
||||
it("should clone object and log lockStrings", function () {
|
||||
const expected = { name: "Module", lockStrings: "stringLock" };
|
||||
const obj = clone(expected);
|
||||
expect(obj).to.deep.equal(expected);
|
||||
expect(expected === obj).to.equal(false);
|
||||
@@ -105,4 +107,3 @@ describe("File js/class", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -1,12 +1,12 @@
|
||||
const expect = require("chai").expect;
|
||||
const deprecated = require("../../../js/deprecated");
|
||||
|
||||
describe("Deprecated", function() {
|
||||
it("should be an object", function() {
|
||||
describe("Deprecated", function () {
|
||||
it("should be an object", function () {
|
||||
expect(deprecated).to.be.an("object");
|
||||
});
|
||||
|
||||
it("should contain configs array with deprecated options as strings", function() {
|
||||
it("should contain configs array with deprecated options as strings", function () {
|
||||
expect(deprecated.configs).to.be.an("array");
|
||||
for (let option of deprecated.configs) {
|
||||
expect(option).to.be.an("string");
|
||||
|
@@ -1,13 +1,13 @@
|
||||
const expect = require("chai").expect;
|
||||
const path = require("path");
|
||||
const helmet = require("helmet");
|
||||
const {JSDOM} = require("jsdom");
|
||||
const { JSDOM } = require("jsdom");
|
||||
const express = require("express");
|
||||
|
||||
describe("Translator", function() {
|
||||
describe("Translator", function () {
|
||||
let server;
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
const app = express();
|
||||
app.use(helmet());
|
||||
app.use(function (req, res, next) {
|
||||
@@ -19,42 +19,42 @@ describe("Translator", function() {
|
||||
server = app.listen(3000);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
server.close();
|
||||
});
|
||||
|
||||
describe("translate", function() {
|
||||
describe("translate", function () {
|
||||
const translations = {
|
||||
"MMM-Module": {
|
||||
"Hello": "Hallo",
|
||||
Hello: "Hallo",
|
||||
"Hello {username}": "Hallo {username}"
|
||||
}
|
||||
};
|
||||
|
||||
const coreTranslations = {
|
||||
"Hello": "XXX",
|
||||
Hello: "XXX",
|
||||
"Hello {username}": "XXX",
|
||||
"FOO": "Foo",
|
||||
FOO: "Foo",
|
||||
"BAR {something}": "Bar {something}"
|
||||
};
|
||||
|
||||
const translationsFallback = {
|
||||
"MMM-Module": {
|
||||
"Hello": "XXX",
|
||||
Hello: "XXX",
|
||||
"Hello {username}": "XXX",
|
||||
"FOO": "XXX",
|
||||
FOO: "XXX",
|
||||
"BAR {something}": "XXX",
|
||||
"A key": "A translation"
|
||||
}
|
||||
};
|
||||
|
||||
const coreTranslationsFallback = {
|
||||
"FOO": "XXX",
|
||||
FOO: "XXX",
|
||||
"BAR {something}": "XXX",
|
||||
"Hello": "XXX",
|
||||
Hello: "XXX",
|
||||
"Hello {username}": "XXX",
|
||||
"A key": "XXX",
|
||||
"Fallback": "core fallback"
|
||||
Fallback: "core fallback"
|
||||
};
|
||||
|
||||
function setTranslations(Translator) {
|
||||
@@ -64,84 +64,78 @@ describe("Translator", function() {
|
||||
Translator.coreTranslationsFallback = coreTranslationsFallback;
|
||||
}
|
||||
|
||||
it("should return custom module translation", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return custom module translation", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({name: "MMM-Module"}, "Hello");
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "Hello");
|
||||
expect(translation).to.be.equal("Hallo");
|
||||
translation = Translator.translate({name: "MMM-Module"}, "Hello {username}", {username: "fewieden"});
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}", { username: "fewieden" });
|
||||
expect(translation).to.be.equal("Hallo fewieden");
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return core translation", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return core translation", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({name: "MMM-Module"}, "FOO");
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "FOO");
|
||||
expect(translation).to.be.equal("Foo");
|
||||
translation = Translator.translate({name: "MMM-Module"}, "BAR {something}", {something: "Lorem Ipsum"});
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "BAR {something}", { something: "Lorem Ipsum" });
|
||||
expect(translation).to.be.equal("Bar Lorem Ipsum");
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return custom module translation fallback", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return custom module translation fallback", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({name: "MMM-Module"}, "A key");
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "A key");
|
||||
expect(translation).to.be.equal("A translation");
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return core translation fallback", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return core translation fallback", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({name: "MMM-Module"}, "Fallback");
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Fallback");
|
||||
expect(translation).to.be.equal("core fallback");
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return translation with placeholder for missing variables", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return translation with placeholder for missing variables", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({name: "MMM-Module"}, "Hello {username}");
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}");
|
||||
expect(translation).to.be.equal("Hallo {username}");
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return key if no translation was found", function(done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator} = dom.window;
|
||||
it("should return key if no translation was found", function (done) {
|
||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({name: "MMM-Module"}, "MISSING");
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
|
||||
expect(translation).to.be.equal("MISSING");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
describe("load", function() {
|
||||
describe("load", function () {
|
||||
const mmm = {
|
||||
name: "TranslationTest",
|
||||
file(file) {
|
||||
@@ -149,14 +143,13 @@ describe("Translator", function() {
|
||||
}
|
||||
};
|
||||
|
||||
it("should load translations", 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;
|
||||
it("should load translations", 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 = "TranslationTest.json";
|
||||
|
||||
Translator.load(mmm, file, false, function() {
|
||||
Translator.load(mmm, file, false, function () {
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
|
||||
expect(Translator.translations[mmm.name]).to.be.deep.equal(json);
|
||||
done();
|
||||
@@ -164,14 +157,13 @@ describe("Translator", function() {
|
||||
};
|
||||
});
|
||||
|
||||
it("should load translation fallbacks", 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;
|
||||
it("should load translation fallbacks", 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 = "TranslationTest.json";
|
||||
|
||||
Translator.load(mmm, file, true, function() {
|
||||
Translator.load(mmm, file, true, function () {
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
|
||||
expect(Translator.translationsFallback[mmm.name]).to.be.deep.equal(json);
|
||||
done();
|
||||
@@ -179,34 +171,32 @@ 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;
|
||||
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() {
|
||||
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"
|
||||
'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" });
|
||||
dom.window.onload = function() {
|
||||
const {Translator, XMLHttpRequest} = dom.window;
|
||||
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" });
|
||||
dom.window.onload = function () {
|
||||
const { Translator, XMLHttpRequest } = dom.window;
|
||||
const file = "TranslationTest.json";
|
||||
|
||||
XMLHttpRequest.prototype.send = function() {
|
||||
XMLHttpRequest.prototype.send = function () {
|
||||
throw "Shouldn't load files";
|
||||
};
|
||||
|
||||
@@ -214,7 +204,7 @@ describe("Translator", function() {
|
||||
Hello: "Hallo"
|
||||
};
|
||||
|
||||
Translator.load(mmm, file, false, function() {
|
||||
Translator.load(mmm, file, false, function () {
|
||||
expect(Translator.translations[mmm.name]).to.be.undefined;
|
||||
expect(Translator.translationsFallback[mmm.name]).to.be.deep.equal({
|
||||
Hello: "Hallo"
|
||||
@@ -225,17 +215,19 @@ describe("Translator", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslations", function() {
|
||||
it("should load core translations and fallback", function(done) {
|
||||
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
describe("loadCoreTranslations", function () {
|
||||
it("should load core translations and fallback", function (done) {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
Translator.loadCoreTranslations("en");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
expect(Translator.coreTranslations).to.be.deep.equal(en);
|
||||
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
|
||||
done();
|
||||
@@ -243,16 +235,18 @@ describe("Translator", function() {
|
||||
};
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", function(done) {
|
||||
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
it("should load core fallback if language cannot be found", function (done) {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
Translator.loadCoreTranslations("MISSINGLANG");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
expect(Translator.coreTranslations).to.be.deep.equal({});
|
||||
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
|
||||
done();
|
||||
@@ -261,32 +255,36 @@ describe("Translator", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslationsFallback", function() {
|
||||
it("should load core translations fallback", function(done) {
|
||||
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
describe("loadCoreTranslationsFallback", function () {
|
||||
it("should load core translations fallback", function (done) {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; 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;
|
||||
Translator.loadCoreTranslationsFallback();
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", function(done) {
|
||||
const dom = new JSDOM(`<script>var translations = {}; 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;
|
||||
it("should load core fallback if language cannot be found", function (done) {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {}; 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;
|
||||
Translator.loadCoreTranslations();
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
|
||||
done();
|
||||
}, 500);
|
||||
|
@@ -2,34 +2,34 @@ var expect = require("chai").expect;
|
||||
var Utils = require("../../../js/utils.js");
|
||||
var colors = require("colors/safe");
|
||||
|
||||
describe("Utils", function() {
|
||||
describe("colors", function() {
|
||||
describe("Utils", function () {
|
||||
describe("colors", function () {
|
||||
var colorsEnabled = colors.enabled;
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(function () {
|
||||
colors.enabled = colorsEnabled;
|
||||
});
|
||||
|
||||
it("should have info, warn and error properties", function() {
|
||||
it("should have info, warn and error properties", function () {
|
||||
expect(Utils.colors).to.have.property("info");
|
||||
expect(Utils.colors).to.have.property("warn");
|
||||
expect(Utils.colors).to.have.property("error");
|
||||
});
|
||||
|
||||
it("properties should be functions", function() {
|
||||
it("properties should be functions", function () {
|
||||
expect(Utils.colors.info).to.be.a("function");
|
||||
expect(Utils.colors.warn).to.be.a("function");
|
||||
expect(Utils.colors.error).to.be.a("function");
|
||||
});
|
||||
|
||||
it("should print colored message in supported consoles", function() {
|
||||
it("should print colored message in supported consoles", function () {
|
||||
colors.enabled = true;
|
||||
expect(Utils.colors.info("some informations")).to.be.equal("\u001b[34msome informations\u001b[39m");
|
||||
expect(Utils.colors.warn("a warning")).to.be.equal("\u001b[33ma warning\u001b[39m");
|
||||
expect(Utils.colors.error("ERROR!")).to.be.equal("\u001b[31mERROR!\u001b[39m");
|
||||
});
|
||||
|
||||
it("should print message in unsupported consoles", function() {
|
||||
it("should print message in unsupported consoles", function () {
|
||||
colors.enabled = false;
|
||||
expect(Utils.colors.info("some informations")).to.be.equal("some informations");
|
||||
expect(Utils.colors.warn("a warning")).to.be.equal("a warning");
|
||||
|
@@ -2,8 +2,7 @@ const expect = require("chai").expect;
|
||||
|
||||
global.moment = require("moment");
|
||||
|
||||
describe("Functions into modules/default/calendar/calendar.js", function() {
|
||||
|
||||
describe("Functions into modules/default/calendar/calendar.js", function () {
|
||||
// Fake for use by calendar.js
|
||||
Module = {};
|
||||
Module.definitions = {};
|
||||
@@ -11,93 +10,93 @@ describe("Functions into modules/default/calendar/calendar.js", function() {
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
// load calendar.js
|
||||
require("../../../modules/default/calendar/calendar.js");
|
||||
});
|
||||
|
||||
describe("capFirst", function() {
|
||||
describe("capFirst", function () {
|
||||
const words = {
|
||||
"rodrigo": "Rodrigo",
|
||||
rodrigo: "Rodrigo",
|
||||
"123m": "123m",
|
||||
"magic mirror": "Magic mirror",
|
||||
",a": ",a",
|
||||
"ñandú": "Ñandú"
|
||||
ñandú: "Ñandú"
|
||||
};
|
||||
|
||||
Object.keys(words).forEach(word => {
|
||||
it(`for '${word}' should return '${words[word]}'`, function() {
|
||||
Object.keys(words).forEach((word) => {
|
||||
it(`for '${word}' should return '${words[word]}'`, function () {
|
||||
expect(Module.definitions.calendar.capFirst(word)).to.equal(words[word]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("getLocaleSpecification", function() {
|
||||
it("Should return a valid moment.LocaleSpecification for a 12-hour format", function() {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification(12)).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||
describe("getLocaleSpecification", function () {
|
||||
it("Should return a valid moment.LocaleSpecification for a 12-hour format", function () {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification(12)).to.deep.equal({ longDateFormat: { LT: "h:mm A" } });
|
||||
});
|
||||
|
||||
it("Should return a valid moment.LocaleSpecification for a 24-hour format", function() {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification(24)).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||
it("Should return a valid moment.LocaleSpecification for a 24-hour format", function () {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification(24)).to.deep.equal({ longDateFormat: { LT: "HH:mm" } });
|
||||
});
|
||||
|
||||
it("Should return the current system locale when called without timeFormat number", function() {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: moment.localeData().longDateFormat("LT")} } );
|
||||
it("Should return the current system locale when called without timeFormat number", function () {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } });
|
||||
});
|
||||
|
||||
it("Should return a 12-hour longDateFormat when using the 'en' locale", function() {
|
||||
it("Should return a 12-hour longDateFormat when using the 'en' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("en");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
|
||||
it("Should return a 12-hour longDateFormat when using the 'au' locale", function() {
|
||||
it("Should return a 12-hour longDateFormat when using the 'au' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("au");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
|
||||
it("Should return a 12-hour longDateFormat when using the 'eg' locale", function() {
|
||||
it("Should return a 12-hour longDateFormat when using the 'eg' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("eg");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
|
||||
it("Should return a 24-hour longDateFormat when using the 'nl' locale", function() {
|
||||
it("Should return a 24-hour longDateFormat when using the 'nl' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("nl");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
|
||||
it("Should return a 24-hour longDateFormat when using the 'fr' locale", function() {
|
||||
it("Should return a 24-hour longDateFormat when using the 'fr' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("fr");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
|
||||
it("Should return a 24-hour longDateFormat when using the 'uk' locale", function() {
|
||||
it("Should return a 24-hour longDateFormat when using the 'uk' locale", function () {
|
||||
var localeBackup = moment.locale();
|
||||
moment.locale("uk");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } });
|
||||
moment.locale(localeBackup);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shorten", function() {
|
||||
describe("shorten", function () {
|
||||
const strings = {
|
||||
" String with whitespace at the beginning that needs trimming" : { length: 16, return: "String with whit…" },
|
||||
" String with whitespace at the beginning that needs trimming": { length: 16, return: "String with whit…" },
|
||||
"long string that needs shortening": { length: 16, return: "long string that…" },
|
||||
"short string": { length: 16, return: "short string" },
|
||||
"long string with no maxLength defined": { return: "long string with no maxLength defined" },
|
||||
"long string with no maxLength defined": { return: "long string with no maxLength defined" }
|
||||
};
|
||||
|
||||
Object.keys(strings).forEach(string => {
|
||||
it(`for '${string}' should return '${strings[string].return}'`, function() {
|
||||
Object.keys(strings).forEach((string) => {
|
||||
it(`for '${string}' should return '${strings[string].return}'`, function () {
|
||||
expect(Module.definitions.calendar.shorten(string, strings[string].length)).to.equal(strings[string].return);
|
||||
});
|
||||
});
|
||||
@@ -111,18 +110,15 @@ describe("Functions into modules/default/calendar/calendar.js", function() {
|
||||
});
|
||||
|
||||
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", function () {
|
||||
expect(Module.definitions.calendar.shorten(
|
||||
"This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true",
|
||||
20,
|
||||
true)).to.equal("This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true");
|
||||
expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", 20, true)).to.equal(
|
||||
"This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true"
|
||||
);
|
||||
});
|
||||
|
||||
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", function () {
|
||||
expect(Module.definitions.calendar.shorten(
|
||||
"This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true",
|
||||
undefined,
|
||||
true)).to.equal("This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true");
|
||||
expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", undefined, true)).to.equal(
|
||||
"This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -1,30 +1,32 @@
|
||||
const expect = require("chai").expect;
|
||||
const path = require("path");
|
||||
const {JSDOM} = require("jsdom");
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
describe("Test function cmpVersions in js/module.js", function() {
|
||||
describe("Test function cmpVersions in js/module.js", function () {
|
||||
let cmp;
|
||||
|
||||
before(function(done) {
|
||||
const dom = new JSDOM(`<script>var Class = {extend: function() { return {}; }};</script>\
|
||||
<script src="${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`, { runScripts: "dangerously",
|
||||
resources: "usable" });
|
||||
dom.window.onload = function() {
|
||||
const {cmpVersions} = dom.window;
|
||||
before(function (done) {
|
||||
const dom = new JSDOM(
|
||||
`<script>var Class = {extend: function() { return {}; }};</script>\
|
||||
<script src="${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
const { cmpVersions } = dom.window;
|
||||
cmp = cmpVersions;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return -1 when comparing 2.1 to 2.2", function() {
|
||||
it("should return -1 when comparing 2.1 to 2.2", function () {
|
||||
expect(cmp("2.1", "2.2")).to.equal(-1);
|
||||
});
|
||||
|
||||
it("should be return 0 when comparing 2.2 to 2.2", function() {
|
||||
it("should be return 0 when comparing 2.2 to 2.2", function () {
|
||||
expect(cmp("2.2", "2.2")).to.equal(0);
|
||||
});
|
||||
|
||||
it("should be return 1 when comparing 1.1 to 1.0", function() {
|
||||
it("should be return 1 when comparing 1.1 to 1.0", function () {
|
||||
expect(cmp("1.1", "1.0")).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
@@ -1,8 +1,7 @@
|
||||
/* eslint no-multi-spaces: 0 */
|
||||
var expect = require("chai").expect;
|
||||
|
||||
describe("Functions module currentweather", function() {
|
||||
|
||||
describe("Functions module currentweather", function () {
|
||||
// Fake for use by currentweather.js
|
||||
Module = {};
|
||||
config = {};
|
||||
@@ -11,58 +10,56 @@ describe("Functions module currentweather", function() {
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
||||
before(function(){
|
||||
before(function () {
|
||||
require("../../../modules/default/currentweather/currentweather.js");
|
||||
Module.definitions.currentweather.config = {};
|
||||
});
|
||||
|
||||
describe("roundValue", function() {
|
||||
|
||||
describe("this.config.roundTemp is true", function() {
|
||||
before(function(){
|
||||
describe("roundValue", function () {
|
||||
describe("this.config.roundTemp is true", function () {
|
||||
before(function () {
|
||||
Module.definitions.currentweather.config.roundTemp = true;
|
||||
});
|
||||
|
||||
var values = [
|
||||
// index 0 value
|
||||
// index 1 expect
|
||||
[1 , "1"],
|
||||
[1.0 , "1"],
|
||||
[1.02 , "1"],
|
||||
[10.12 , "10"],
|
||||
[2.0 , "2"],
|
||||
["2.12" , "2"],
|
||||
[10.1 , "10"]
|
||||
[1, "1"],
|
||||
[1.0, "1"],
|
||||
[1.02, "1"],
|
||||
[10.12, "10"],
|
||||
[2.0, "2"],
|
||||
["2.12", "2"],
|
||||
[10.1, "10"]
|
||||
];
|
||||
|
||||
values.forEach(value => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function() {
|
||||
values.forEach((value) => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function () {
|
||||
expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("this.config.roundTemp is false", function() {
|
||||
|
||||
before(function(){
|
||||
describe("this.config.roundTemp is false", function () {
|
||||
before(function () {
|
||||
Module.definitions.currentweather.config.roundTemp = false;
|
||||
});
|
||||
|
||||
var values = [
|
||||
// index 0 value
|
||||
// index 1 expect
|
||||
[1 , "1.0"],
|
||||
[1.0 , "1.0"],
|
||||
[1.02 , "1.0"],
|
||||
[10.12 , "10.1"],
|
||||
[2.0 , "2.0"],
|
||||
["2.12" , "2.1"],
|
||||
[10.1 , "10.1"],
|
||||
[10.10 , "10.1"]
|
||||
[1, "1.0"],
|
||||
[1.0, "1.0"],
|
||||
[1.02, "1.0"],
|
||||
[10.12, "10.1"],
|
||||
[2.0, "2.0"],
|
||||
["2.12", "2.1"],
|
||||
[10.1, "10.1"],
|
||||
[10.1, "10.1"]
|
||||
];
|
||||
|
||||
values.forEach(value => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function() {
|
||||
values.forEach((value) => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function () {
|
||||
expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]);
|
||||
});
|
||||
});
|
||||
|
@@ -1,7 +1,6 @@
|
||||
var expect = require("chai").expect;
|
||||
|
||||
describe("Functions into modules/default/newsfeed/newsfeed.js", function() {
|
||||
|
||||
describe("Functions into modules/default/newsfeed/newsfeed.js", function () {
|
||||
Module = {};
|
||||
Module.definitions = {};
|
||||
Module.register = function (name, moduleDefinition) {
|
||||
@@ -11,21 +10,20 @@ describe("Functions into modules/default/newsfeed/newsfeed.js", function() {
|
||||
// load newsfeed.js
|
||||
require("../../../modules/default/newsfeed/newsfeed.js");
|
||||
|
||||
describe("capitalizeFirstLetter", function() {
|
||||
describe("capitalizeFirstLetter", function () {
|
||||
const words = {
|
||||
"rodrigo": "Rodrigo",
|
||||
rodrigo: "Rodrigo",
|
||||
"123m": "123m",
|
||||
"magic mirror": "Magic mirror",
|
||||
",a": ",a",
|
||||
"ñandú": "Ñandú",
|
||||
ñandú: "Ñandú",
|
||||
".!": ".!"
|
||||
};
|
||||
|
||||
Object.keys(words).forEach(word => {
|
||||
it(`for ${word} should return ${words[word]}`, function() {
|
||||
Object.keys(words).forEach((word) => {
|
||||
it(`for ${word} should return ${words[word]}`, function () {
|
||||
expect(Module.definitions.newsfeed.capitalizeFirstLetter(word)).to.equal(words[word]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
/* eslint no-multi-spaces: 0 */
|
||||
var expect = require("chai").expect;
|
||||
|
||||
describe("Functions module weatherforecast", function() {
|
||||
|
||||
before(function(){
|
||||
describe("Functions module weatherforecast", function () {
|
||||
before(function () {
|
||||
Module = {};
|
||||
config = {};
|
||||
Module.definitions = {};
|
||||
@@ -14,53 +13,51 @@ describe("Functions module weatherforecast", function() {
|
||||
Module.definitions.weatherforecast.config = {};
|
||||
});
|
||||
|
||||
describe("roundValue", function() {
|
||||
|
||||
describe("this.config.roundTemp is true", function() {
|
||||
before(function(){
|
||||
describe("roundValue", function () {
|
||||
describe("this.config.roundTemp is true", function () {
|
||||
before(function () {
|
||||
Module.definitions.weatherforecast.config.roundTemp = true;
|
||||
});
|
||||
|
||||
var values = [
|
||||
// index 0 value
|
||||
// index 1 expect
|
||||
[1 , "1"],
|
||||
[1.0 , "1"],
|
||||
[1.02 , "1"],
|
||||
[10.12 , "10"],
|
||||
[2.0 , "2"],
|
||||
["2.12" , "2"],
|
||||
[10.1 , "10"]
|
||||
[1, "1"],
|
||||
[1.0, "1"],
|
||||
[1.02, "1"],
|
||||
[10.12, "10"],
|
||||
[2.0, "2"],
|
||||
["2.12", "2"],
|
||||
[10.1, "10"]
|
||||
];
|
||||
|
||||
values.forEach(value => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function() {
|
||||
values.forEach((value) => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function () {
|
||||
expect(Module.definitions.weatherforecast.roundValue(value[0])).to.equal(value[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("this.config.roundTemp is false", function() {
|
||||
|
||||
before(function(){
|
||||
describe("this.config.roundTemp is false", function () {
|
||||
before(function () {
|
||||
Module.definitions.weatherforecast.config.roundTemp = false;
|
||||
});
|
||||
|
||||
var values = [
|
||||
// index 0 value
|
||||
// index 1 expect
|
||||
[1 , "1.0"],
|
||||
[1.0 , "1.0"],
|
||||
[1.02 , "1.0"],
|
||||
[10.12 , "10.1"],
|
||||
[2.0 , "2.0"],
|
||||
["2.12" , "2.1"],
|
||||
[10.1 , "10.1"],
|
||||
[10.10 , "10.1"]
|
||||
[1, "1.0"],
|
||||
[1.0, "1.0"],
|
||||
[1.02, "1.0"],
|
||||
[10.12, "10.1"],
|
||||
[2.0, "2.0"],
|
||||
["2.12", "2.1"],
|
||||
[10.1, "10.1"],
|
||||
[10.1, "10.1"]
|
||||
];
|
||||
|
||||
values.forEach(value => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function() {
|
||||
values.forEach((value) => {
|
||||
it(`for ${value[0]} should be return ${value[1]}`, function () {
|
||||
expect(Module.definitions.weatherforecast.roundValue(value[0])).to.equal(value[1]);
|
||||
});
|
||||
});
|
||||
|
@@ -3,7 +3,7 @@ var path = require("path");
|
||||
var expect = require("chai").expect;
|
||||
var vm = require("vm");
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
var basedir = path.join(__dirname, "../../..");
|
||||
|
||||
var fileName = "js/app.js";
|
||||
@@ -15,15 +15,19 @@ before(function() {
|
||||
__dirname: path.dirname(filePath),
|
||||
global: {},
|
||||
console: {
|
||||
log: function() { /*console.log("console.log(", arguments, ")");*/ }
|
||||
log: function () {
|
||||
/*console.log("console.log(", arguments, ")");*/
|
||||
}
|
||||
},
|
||||
process: {
|
||||
on: function() { /*console.log("process.on called with: ", arguments);*/ },
|
||||
on: function () {
|
||||
/*console.log("process.on called with: ", arguments);*/
|
||||
},
|
||||
env: {}
|
||||
}
|
||||
};
|
||||
|
||||
this.sandbox.require = function(filename) {
|
||||
this.sandbox.require = function (filename) {
|
||||
// This modifies the global slightly,
|
||||
// but supplies vm with essential code
|
||||
return require(filename);
|
||||
@@ -32,32 +36,21 @@ before(function() {
|
||||
vm.runInNewContext(code, this.sandbox, fileName);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
//console.log(global);
|
||||
});
|
||||
|
||||
describe("Default modules set in modules/default/defaultmodules.js", function() {
|
||||
describe("Default modules set in modules/default/defaultmodules.js", function () {
|
||||
var expectedDefaultModules = ["alert", "calendar", "clock", "compliments", "currentweather", "helloworld", "newsfeed", "weatherforecast", "updatenotification"];
|
||||
|
||||
var expectedDefaultModules = [
|
||||
"alert",
|
||||
"calendar",
|
||||
"clock",
|
||||
"compliments",
|
||||
"currentweather",
|
||||
"helloworld",
|
||||
"newsfeed",
|
||||
"weatherforecast",
|
||||
"updatenotification"
|
||||
];
|
||||
|
||||
expectedDefaultModules.forEach(defaultModule => {
|
||||
it(`contains default module "${defaultModule}"`, function() {
|
||||
expectedDefaultModules.forEach((defaultModule) => {
|
||||
it(`contains default module "${defaultModule}"`, function () {
|
||||
expect(this.sandbox.defaultModules).to.include(defaultModule);
|
||||
});
|
||||
});
|
||||
|
||||
expectedDefaultModules.forEach(defaultModule => {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, function() {
|
||||
expectedDefaultModules.forEach((defaultModule) => {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, function () {
|
||||
expect(fs.existsSync(path.join(this.sandbox.global.root_path, "modules/default", defaultModule))).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
@@ -3,7 +3,7 @@ var path = require("path");
|
||||
var expect = require("chai").expect;
|
||||
var vm = require("vm");
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
var basedir = path.join(__dirname, "../../..");
|
||||
|
||||
var fileName = "js/app.js";
|
||||
@@ -15,15 +15,19 @@ before(function() {
|
||||
__dirname: path.dirname(filePath),
|
||||
global: {},
|
||||
console: {
|
||||
log: function() { /*console.log("console.log(", arguments, ")");*/ }
|
||||
log: function () {
|
||||
/*console.log("console.log(", arguments, ")");*/
|
||||
}
|
||||
},
|
||||
process: {
|
||||
on: function() { /*console.log("process.on called with: ", arguments);*/ },
|
||||
on: function () {
|
||||
/*console.log("process.on called with: ", arguments);*/
|
||||
},
|
||||
env: {}
|
||||
}
|
||||
};
|
||||
|
||||
this.sandbox.require = function(filename) {
|
||||
this.sandbox.require = function (filename) {
|
||||
// This modifies the global slightly,
|
||||
// but supplies vm with essential code
|
||||
return require(filename);
|
||||
@@ -32,36 +36,28 @@ before(function() {
|
||||
vm.runInNewContext(code, this.sandbox, fileName);
|
||||
});
|
||||
|
||||
after(function() {
|
||||
after(function () {
|
||||
//console.log(global);
|
||||
});
|
||||
|
||||
describe("'global.root_path' set in js/app.js", function() {
|
||||
var expectedSubPaths = [
|
||||
"modules",
|
||||
"serveronly",
|
||||
"js",
|
||||
"js/app.js",
|
||||
"js/main.js",
|
||||
"js/electron.js",
|
||||
"config"
|
||||
];
|
||||
describe("'global.root_path' set in js/app.js", function () {
|
||||
var expectedSubPaths = ["modules", "serveronly", "js", "js/app.js", "js/main.js", "js/electron.js", "config"];
|
||||
|
||||
expectedSubPaths.forEach(subpath => {
|
||||
it(`contains a file/folder "${subpath}"`, function() {
|
||||
expectedSubPaths.forEach((subpath) => {
|
||||
it(`contains a file/folder "${subpath}"`, function () {
|
||||
expect(fs.existsSync(path.join(this.sandbox.global.root_path, subpath))).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not modify global.root_path for testing", function() {
|
||||
it("should not modify global.root_path for testing", function () {
|
||||
expect(global.root_path).to.equal(undefined);
|
||||
});
|
||||
|
||||
it("should not modify global.version for testing", function() {
|
||||
it("should not modify global.version for testing", function () {
|
||||
expect(global.version).to.equal(undefined);
|
||||
});
|
||||
|
||||
it("should expect the global.version equals package.json file", function() {
|
||||
it("should expect the global.version equals package.json file", function () {
|
||||
const versionPackage = JSON.parse(fs.readFileSync("package.json", "utf8")).version;
|
||||
expect(this.sandbox.global.version).to.equal(versionPackage);
|
||||
});
|
||||
|
Reference in New Issue
Block a user