mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-26 08:01:29 +00:00
Use template literals instead of string concatenation (#3066)
We have used it inconsistently till now. Template literals are more modern and easier to maintain in my opinion. Because that's a large amount of changes, here's a way to reproduce it: I added the rule `"prefer-template": "error"` to the `.eslintrc.json` and did an autofix. Since this caused a new problem in line 409 of `newsfeed.js`, I reversed it in that line and also removed the rule from the eslint config file. The rule is described here: https://eslint.org/docs/latest/rules/prefer-template Note: I've played around with some other linter rules as well, and some seem to point to some specific, non-cosmetic, issues. But before I dive even deeper and then introduce even bigger and hardly understandable changes at once, I thought I'd start with this simple cosmetic rule.
This commit is contained in:
committed by
GitHub
parent
8f8945d418
commit
d276a7ddb9
@@ -3,7 +3,7 @@ const helpers = require("./helpers/global-setup");
|
||||
describe("All font files from roboto.css should be downloadable", () => {
|
||||
const fontFiles = [];
|
||||
// Statements below filters out all 'url' lines in the CSS file
|
||||
const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
|
||||
const fileContent = require("fs").readFileSync(`${__dirname}/../../fonts/roboto.css`, "utf8");
|
||||
const regex = /\burl\(['"]([^'"]+)['"]\)/g;
|
||||
let match = regex.exec(fileContent);
|
||||
while (match !== null) {
|
||||
@@ -21,7 +21,7 @@ describe("All font files from roboto.css should be downloadable", () => {
|
||||
});
|
||||
|
||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", async (fontFile) => {
|
||||
const fontUrl = "http://localhost:8080/fonts/" + fontFile;
|
||||
const fontUrl = `http://localhost:8080/fonts/${fontFile}`;
|
||||
const res = await helpers.fetch(fontUrl);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
@@ -12,7 +12,7 @@ app.use(basicAuth);
|
||||
|
||||
// Set available directories
|
||||
const directories = ["/tests/configs", "/tests/mocks"];
|
||||
const rootPath = path.resolve(__dirname + "/../../../");
|
||||
const rootPath = path.resolve(`${__dirname}/../../../`);
|
||||
|
||||
for (let directory of directories) {
|
||||
app.use(directory, express.static(path.resolve(rootPath + directory)));
|
||||
|
@@ -28,7 +28,7 @@ exports.stopApplication = async () => {
|
||||
|
||||
exports.getDocument = () => {
|
||||
return new Promise((resolve) => {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
const url = `http://${config.address || "localhost"}:${config.port || "8080"}`;
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
dom.window.fetch = corefetch;
|
||||
|
@@ -91,7 +91,7 @@ describe("Calendar module", () => {
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it('should contain text "Mar 25th" in timezone UTC ' + -i, async () => {
|
||||
it(`should contain text "Mar 25th" in timezone UTC ${-i}`, async () => {
|
||||
await testTextContain(".calendar", "Mar 25th");
|
||||
});
|
||||
});
|
||||
|
@@ -89,7 +89,7 @@ describe("Clock module", () => {
|
||||
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = "Week " + currentWeekNumber;
|
||||
const weekToShow = `Week ${currentWeekNumber}`;
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
|
@@ -13,14 +13,14 @@ describe("Weather module: Weather Forecast", () => {
|
||||
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
it(`should render day ${day}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
it("should render icon " + icon, async () => {
|
||||
it(`should render icon ${icon}`, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
@@ -28,21 +28,21 @@ describe("Weather module: Weather Forecast", () => {
|
||||
|
||||
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
for (const [index, temp] of maxTemps.entries()) {
|
||||
it("should render max temperature " + temp, async () => {
|
||||
it(`should render max temperature ${temp}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
for (const [index, temp] of minTemps.entries()) {
|
||||
it("should render min temperature " + temp, async () => {
|
||||
it(`should render min temperature ${temp}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
it("should render fading of rows with opacity=" + opacity, async () => {
|
||||
it(`should render fading of rows with opacity=${opacity}`, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
@@ -57,7 +57,7 @@ describe("Weather module: Weather Forecast", () => {
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
it(`should render day ${day}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
@@ -83,7 +83,7 @@ describe("Weather module: Weather Forecast", () => {
|
||||
const precipitations = [undefined, "2.51 mm"];
|
||||
for (const [index, precipitation] of precipitations.entries()) {
|
||||
if (precipitation) {
|
||||
it("should render precipitation amount " + precipitation, async () => {
|
||||
it(`should render precipitation amount ${precipitation}`, async () => {
|
||||
await weatherFunc.getText(`.weather table tr:nth-child(${index + 1}) td.precipitation-amount`, precipitation);
|
||||
});
|
||||
}
|
||||
@@ -98,7 +98,7 @@ describe("Weather module: Weather Forecast", () => {
|
||||
describe("Temperature units", () => {
|
||||
const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
|
||||
it(`should render custom decimalSymbol = '_' for temp ${temp}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
@@ -108,7 +108,7 @@ describe("Weather module: Weather Forecast", () => {
|
||||
const precipitations = [undefined, "0.10 in"];
|
||||
for (const [index, precipitation] of precipitations.entries()) {
|
||||
if (precipitation) {
|
||||
it("should render precipitation amount " + precipitation, async () => {
|
||||
it(`should render precipitation amount ${precipitation}`, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td.precipitation-amount`, precipitation);
|
||||
});
|
||||
}
|
||||
|
@@ -13,10 +13,10 @@ describe("Position of modules", () => {
|
||||
|
||||
for (const position of positions) {
|
||||
const className = position.replace("_", ".");
|
||||
it("should show text in " + position, async () => {
|
||||
const elem = await helpers.waitForElement("." + className);
|
||||
it(`should show text in ${position}`, async () => {
|
||||
const elem = await helpers.waitForElement(`.${className}`);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Text in " + position);
|
||||
expect(elem.textContent).toContain(`Text in ${position}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -9,11 +9,11 @@ describe("Vendors", () => {
|
||||
});
|
||||
|
||||
describe("Get list vendors", () => {
|
||||
const vendors = require(__dirname + "/../../vendor/vendor.js");
|
||||
const vendors = require(`${__dirname}/../../vendor/vendor.js`);
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 200 HTTP code for vendor "${vendor}"`, async () => {
|
||||
const urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
|
||||
const urlVendor = `http://localhost:8080/vendor/${vendors[vendor]}`;
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
@@ -21,7 +21,7 @@ describe("Vendors", () => {
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, async () => {
|
||||
const urlVendor = "http://localhost:8080/" + vendors[vendor];
|
||||
const urlVendor = `http://localhost:8080/${vendors[vendor]}`;
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
|
Reference in New Issue
Block a user