first commit

This commit is contained in:
2023-09-30 20:18:17 +02:00
commit d5047f6ee0
293 changed files with 40054 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
const TestSequencer = require("@jest/test-sequencer").default;
class CustomSequencer extends TestSequencer {
sort(tests) {
const orderPath = ["unit", "electron", "e2e"];
return tests.sort((testA, testB) => {
let indexA = -1;
let indexB = -1;
const reg = ".*/tests/([^/]*).*";
// move calendar and newsfeed at the end
if (testA.path.includes("e2e/modules/calendar_spec") || testA.path.includes("e2e/modules/newsfeed_spec")) return 1;
if (testB.path.includes("e2e/modules/calendar_spec") || testB.path.includes("e2e/modules/newsfeed_spec")) return -1;
let matchA = new RegExp(reg, "g").exec(testA.path);
if (matchA.length > 0) indexA = orderPath.indexOf(matchA[1]);
let matchB = new RegExp(reg, "g").exec(testB.path);
if (matchB.length > 0) indexB = orderPath.indexOf(matchB[1]);
if (indexA === indexB) return 0;
if (indexA === -1) return 1;
if (indexB === -1) return -1;
return indexA < indexB ? -1 : 1;
});
}
}
module.exports = CustomSequencer;
+43
View File
@@ -0,0 +1,43 @@
const fs = require("fs");
const path = require("path");
const _ = require("lodash");
/**
* @param {string} type what data to read, can be "current" "forecast" or "hourly
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked current weather data
*/
const readMockData = (type, extendedData = {}) => {
let fileName;
switch (type) {
case "forecast":
fileName = "weather_forecast.json";
break;
case "hourly":
fileName = "weather_hourly.json";
break;
case "current":
default:
fileName = "weather_current.json";
break;
}
return JSON.stringify(_.merge({}, JSON.parse(fs.readFileSync(path.resolve(`${__dirname}/../mocks/${fileName}`)).toString()), extendedData));
};
const injectMockData = (configFileName, extendedData = {}) => {
let mockWeather;
if (configFileName.includes("forecast")) {
mockWeather = readMockData("forecast", extendedData);
} else if (configFileName.includes("hourly")) {
mockWeather = readMockData("hourly", extendedData);
} else {
mockWeather = readMockData("current", extendedData);
}
let content = fs.readFileSync(path.resolve(`${__dirname}../../../${configFileName}`)).toString();
content = content.replace("#####WEATHERDATA#####", mockWeather);
fs.writeFileSync(path.resolve(`${__dirname}../../../config/config.js`), content);
};
module.exports = { injectMockData };