Merge pull request #2082 from rejas/istanbul

Add test coverage tool Istanbul
This commit is contained in:
Michael Teeuw 2020-07-17 16:25:00 +02:00 committed by GitHub
commit 275825cfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 1024 additions and 1233 deletions

6
.gitignore vendored
View File

@ -1,5 +1,4 @@
# Various Node ignoramuses.
logs
*.log
npm-debug.log*
@ -13,9 +12,11 @@ build/Release
/node_modules/**/*
fonts/node_modules/**/*
vendor/node_modules/**/*
!/tests/node_modules/**/*
jspm_modules
.npm
.node_repl_history
.nyc_output/
# Visual Studio Code ignoramuses.
.vscode/
@ -53,7 +54,6 @@ Temporary Items
.apdisk
# Various Linux ignoramuses.
.fuse_hidden*
.directory
.Trash-*
@ -76,5 +76,3 @@ Temporary Items
*.orig
*.rej
*.bak
!/tests/node_modules/**/*

View File

@ -11,6 +11,7 @@ _This release is scheduled to be released on 2020-10-01._
### Added
- Test coverage with Istanbul, run it with `npm run test:coverage`.
- Add lithuanian language.
- Added support in weatherforecast for OpenWeather onecall API.

View File

@ -19,92 +19,12 @@ var Translator = (function () {
xhr.open("GET", file, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
callback(JSON.parse(stripComments(xhr.responseText)));
callback(JSON.parse(xhr.responseText));
}
};
xhr.send(null);
}
/* loadJSON(str, options)
* Remove any commenting from a json file so it can be parsed.
*
* argument str string - The string that contains json with comments.
* argument opts function - Strip options.
*
* return the stripped string.
*/
function stripComments(str, opts) {
// strip comments copied from: https://github.com/sindresorhus/strip-json-comments
var singleComment = 1;
var multiComment = 2;
function stripWithoutWhitespace() {
return "";
}
function stripWithWhitespace(str, start, end) {
return str.slice(start, end).replace(/\S/g, " ");
}
opts = opts || {};
var currentChar;
var nextChar;
var insideString = false;
var insideComment = false;
var offset = 0;
var ret = "";
var strip = opts.whitespace === false ? stripWithoutWhitespace : stripWithWhitespace;
for (var i = 0; i < str.length; i++) {
currentChar = str[i];
nextChar = str[i + 1];
if (!insideComment && currentChar === '"') {
var escaped = str[i - 1] === "\\" && str[i - 2] !== "\\";
if (!escaped) {
insideString = !insideString;
}
}
if (insideString) {
continue;
}
if (!insideComment && currentChar + nextChar === "//") {
ret += str.slice(offset, i);
offset = i;
insideComment = singleComment;
i++;
} else if (insideComment === singleComment && currentChar + nextChar === "\r\n") {
i++;
insideComment = false;
ret += strip(str, offset, i);
offset = i;
continue;
} else if (insideComment === singleComment && currentChar === "\n") {
insideComment = false;
ret += strip(str, offset, i);
offset = i;
} else if (!insideComment && currentChar + nextChar === "/*") {
ret += str.slice(offset, i);
offset = i;
insideComment = multiComment;
i++;
continue;
} else if (insideComment === multiComment && currentChar + nextChar === "*/") {
i++;
insideComment = false;
ret += strip(str, offset, i + 1);
offset = i + 1;
continue;
}
}
return ret + (insideComment ? strip(str.substr(offset)) : str.substr(offset));
}
return {
coreTranslations: {},
coreTranslationsFallback: {},

941
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,9 +9,10 @@
"install": "echo \"Installing vendor files ...\n\" && cd vendor && npm install --loglevel=error",
"install-fonts": "echo \"Installing fonts ...\n\" && cd fonts && npm install --loglevel=error",
"postinstall": "npm run install-fonts && echo \"MagicMirror installation finished successfully! \n\"",
"test": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests --recursive",
"test:unit": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/unit --recursive",
"test:e2e": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/e2e --recursive",
"test": "NODE_ENV=test mocha tests --recursive",
"test:coverage": "NODE_ENV=test nyc mocha tests --recursive --timeout=3000",
"test:e2e": "NODE_ENV=test mocha tests/e2e --recursive",
"test:unit": "NODE_ENV=test mocha tests/unit --recursive",
"test:prettier": "prettier --check **/*.{js,css,json,md,yml}",
"test:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json --quiet",
"test:css": "stylelint css/main.css modules/default/**/*.css --config .stylelintrc.json",
@ -54,6 +55,7 @@
"mocha": "^7.1.2",
"mocha-each": "^2.0.1",
"mocha-logger": "^1.0.6",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"spectron": "^8.0.0",
@ -68,18 +70,18 @@
"dependencies": {
"colors": "^1.1.2",
"console-stamp": "^0.2.9",
"eslint": "^7.3.0",
"eslint": "^7.4.0",
"express": "^4.16.2",
"express-ipfilter": "^1.0.1",
"feedme": "latest",
"helmet": "^3.21.2",
"helmet": "^3.23.3",
"ical": "^0.8.0",
"iconv-lite": "latest",
"lodash": "^4.17.15",
"lodash": "^4.17.19",
"module-alias": "^2.2.2",
"moment": "latest",
"request": "^2.88.2",
"rrule": "^2.6.2",
"rrule": "^2.6.4",
"rrule-alt": "^2.2.8",
"simple-git": "^1.85.0",
"socket.io": "^2.1.1",

View File

@ -1,7 +1,7 @@
var path = require("path");
var auth = require("http-auth");
var express = require("express");
var app = express();
const path = require("path");
const auth = require("http-auth");
const express = require("express");
const app = express();
var server;

View File

@ -171,25 +171,6 @@ 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" });
dom.window.onload = function () {
@ -205,7 +186,7 @@ describe("Translator", function () {
};
Translator.load(mmm, file, false, function () {
expect(Translator.translations[mmm.name]).to.be.undefined;
expect(Translator.translations[mmm.name]).to.be.equal(undefined);
expect(Translator.translationsFallback[mmm.name]).to.be.deep.equal({
Hello: "Hallo"
});

View File

@ -1,6 +1,6 @@
var expect = require("chai").expect;
var Utils = require("../../../js/utils.js");
var colors = require("colors/safe");
const expect = require("chai").expect;
const Utils = require("../../../js/utils.js");
const colors = require("colors/safe");
describe("Utils", function () {
describe("colors", function () {

View File

@ -120,5 +120,11 @@ describe("Functions into modules/default/calendar/calendar.js", function () {
"This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true"
);
});
it("should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", function () {
expect(Module.definitions.calendar.shorten("This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", undefined, true, 2)).to.equal(
"This is a wrapEvent and <br>maxTitleLines test. Should wrap and &hellip;"
);
});
});
});

View File

@ -1,5 +1,5 @@
/* eslint no-multi-spaces: 0 */
var expect = require("chai").expect;
const expect = require("chai").expect;
describe("Functions module currentweather", function () {
// Fake for use by currentweather.js

View File

@ -1,4 +1,4 @@
var expect = require("chai").expect;
const expect = require("chai").expect;
describe("Functions into modules/default/newsfeed/newsfeed.js", function () {
Module = {};

View File

@ -1,5 +1,5 @@
/* eslint no-multi-spaces: 0 */
var expect = require("chai").expect;
const expect = require("chai").expect;
describe("Functions module weatherforecast", function () {
before(function () {

View File

@ -1,7 +1,7 @@
var fs = require("fs");
var path = require("path");
var expect = require("chai").expect;
var vm = require("vm");
const fs = require("fs");
const path = require("path");
const expect = require("chai").expect;
const vm = require("vm");
before(function () {
var basedir = path.join(__dirname, "../../..");

View File

@ -1,7 +1,7 @@
var fs = require("fs");
var path = require("path");
var expect = require("chai").expect;
var vm = require("vm");
const fs = require("fs");
const path = require("path");
const expect = require("chai").expect;
const vm = require("vm");
before(function () {
var basedir = path.join(__dirname, "../../..");

1140
vendor/package-lock.json generated vendored

File diff suppressed because it is too large Load Diff

8
vendor/package.json vendored
View File

@ -10,10 +10,10 @@
"url": "https://github.com/MichMich/MagicMirror/issues"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.3.1",
"moment": "^2.17.1",
"moment-timezone": "^0.5.11",
"nunjucks": "^3.0.1",
"@fortawesome/fontawesome-free": "^5.13.1",
"moment": "^2.27.0",
"moment-timezone": "^0.5.31",
"nunjucks": "^3.2.1",
"suncalc": "^1.8.0",
"weathericons": "^2.1.0"
}