Add no-param-reassign from eslint (#3089)

While waiting for the easterbunny I cleaned up some bad coding practice
:-)

Very open for comments especially regarding the places I commented
myself...

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck 2023-04-16 17:38:39 +02:00 committed by GitHub
parent 979f4ec664
commit 7e58b38ddf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 245 additions and 237 deletions

View File

@ -24,6 +24,7 @@
"rules": {
"eqeqeq": "error",
"import/order": "error",
"no-param-reassign": "error",
"no-prototype-builtins": "off",
"no-throw-literal": "error",
"no-unused-vars": "off",

View File

@ -13,6 +13,7 @@ _This release is scheduled to be released on 2023-07-01._
- Added tests for serveronly
- Set Timezone `Europe/Berlin` in unit tests (needed for new formatTime tests)
- Added no-param-reassign eslint rule and fix warnings
### Removed

View File

@ -205,30 +205,17 @@ function App() {
/**
* Loads all modules.
*
* @param {string[]} modules All modules to be loaded
* @param {Module[]} modules All modules to be loaded
* @returns {Promise} A promise that is resolved when all modules been loaded
*/
async function loadModules(modules) {
return new Promise((resolve) => {
Log.log("Loading module helpers ...");
/**
*
*/
function loadNextModule() {
if (modules.length > 0) {
const nextModule = modules[0];
loadModule(nextModule);
modules = modules.slice(1);
loadNextModule();
} else {
// All modules are loaded
Log.log("All module helpers loaded.");
resolve();
}
for (let module of modules) {
await loadModule(module);
}
loadNextModule();
});
Log.log("All module helpers loaded.");
}
/**
@ -269,11 +256,13 @@ function App() {
Log.setLogLevel(config.logLevel);
let modules = [];
for (const module of config.modules) {
if (!modules.includes(module.module) && !module.disabled) {
modules.push(module.module);
}
}
await loadModules(modules);
httpServer = new Server(config);

View File

@ -230,9 +230,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
*/
const hideModule = function (module, speed, callback, options) {
options = options || {};
const hideModule = function (module, speed, callback, options = {}) {
// set lockString if set in options.
if (options.lockString) {
// Log.log("Has lockstring: " + options.lockString);
@ -277,9 +275,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
*/
const showModule = function (module, speed, callback, options) {
options = options || {};
const showModule = function (module, speed, callback, options = {}) {
// remove lockString if set in options.
if (options.lockString) {
const index = module.lockStrings.indexOf(options.lockString);

View File

@ -378,23 +378,24 @@ const Module = Class.extend({
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
*/
hide: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () {};
}
hide: function (speed, callback, options = {}) {
let usedCallback = callback || function () {};
let usedOptions = options;
callback = callback || function () {};
options = options || {};
if (typeof callback === "object") {
Log.error("Parameter mismatch in module.hide: callback is not an optional parameter!");
usedOptions = callback;
usedCallback = function () {};
}
MM.hideModule(
this,
speed,
() => {
this.suspend();
callback();
usedCallback();
},
options
usedOptions
);
},
@ -406,22 +407,23 @@ const Module = Class.extend({
* @param {object} [options] Optional settings for the show method.
*/
show: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () {};
}
let usedCallback = callback || function () {};
let usedOptions = options;
callback = callback || function () {};
options = options || {};
if (typeof callback === "object") {
Log.error("Parameter mismatch in module.show: callback is not an optional parameter!");
usedOptions = callback;
usedCallback = function () {};
}
MM.showModule(
this,
speed,
() => {
this.resume();
callback();
usedCallback();
},
options
usedOptions
);
}
});

View File

@ -44,10 +44,7 @@ const MMSocket = function (moduleName) {
notificationCallback = callback;
};
this.sendNotification = (notification, payload) => {
if (typeof payload === "undefined") {
payload = {};
}
this.sendNotification = (notification, payload = {}) => {
this.socket.emit(notification, payload);
};
};

View File

@ -15,7 +15,7 @@ const Translator = (function () {
*/
async function loadJSON(file) {
const xhr = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
return new Promise(function (resolve) {
xhr.overrideMimeType("application/json");
xhr.open("GET", file, true);
xhr.onreadystatechange = function () {
@ -49,9 +49,7 @@ const Translator = (function () {
* @param {object} variables The variables to use within the translation template (optional)
* @returns {string} the translated key
*/
translate: function (module, key, variables) {
variables = variables || {}; // Empty object by default
translate: function (module, key, variables = {}) {
/**
* Combines template and variables like:
* template: "Please wait for {timeToWait} before continuing with {work}."
@ -66,10 +64,11 @@ const Translator = (function () {
if (Object.prototype.toString.call(template) !== "[object String]") {
return template;
}
let templateToUse = template;
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
template = variables.fallback;
templateToUse = variables.fallback;
}
return template.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
return templateToUse.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
return varName in variables ? variables[varName] : `{${varName}}`;
});
}

View File

@ -593,15 +593,13 @@ const CalendarFetcherUtils = {
*/
titleFilterApplies: function (title, filter, useRegex, regexFlags) {
if (useRegex) {
let regexFilter = filter;
// Assume if leading slash, there is also trailing slash
if (filter[0] === "/") {
// Strip leading and trailing slashes
filter = filter.substr(1).slice(0, -1);
regexFilter = filter.substr(1).slice(0, -1);
}
filter = new RegExp(filter, regexFlags);
return filter.test(title);
return new RegExp(regexFilter, regexFlags).test(title);
} else {
return title.includes(filter);
}

View File

@ -100,6 +100,7 @@ const CalendarUtils = {
* @returns {string} The transformed title.
*/
titleTransform: function (title, titleReplace) {
let transformedTitle = title;
for (let needle in titleReplace) {
const replacement = titleReplace[needle];
@ -109,9 +110,9 @@ const CalendarUtils = {
needle = new RegExp(regParts[1], regParts[2]);
}
title = title.replace(needle, replacement);
transformedTitle = transformedTitle.replace(needle, replacement);
}
return title;
return transformedTitle;
}
};

View File

@ -25,12 +25,13 @@ const NodeHelper = require("node_helper");
const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings, useCorsProxy) {
let reloadTimer = null;
let items = [];
let reloadIntervalMS = reloadInterval;
let fetchFailedCallback = function () {};
let itemsReceivedCallback = function () {};
if (reloadInterval < 1000) {
reloadInterval = 1000;
if (reloadIntervalMS < 1000) {
reloadIntervalMS = 1000;
}
/* private methods */
@ -89,9 +90,9 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
try {
// 86400000 = 24 hours is mentioned in the docs as maximum value:
const ttlms = Math.min(minutes * 60 * 1000, 86400000);
if (ttlms > reloadInterval) {
reloadInterval = ttlms;
Log.info(`Newsfeed-Fetcher: reloadInterval set to ttl=${reloadInterval} for url ${url}`);
if (ttlms > reloadIntervalMS) {
reloadIntervalMS = ttlms;
Log.info(`Newsfeed-Fetcher: reloadInterval set to ttl=${reloadIntervalMS} for url ${url}`);
}
} catch (error) {
Log.warn(`Newsfeed-Fetcher: feed ttl is no valid integer=${minutes} for url ${url}`);
@ -129,7 +130,7 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
clearTimeout(reloadTimer);
reloadTimer = setTimeout(function () {
fetchNews();
}, reloadInterval);
}, reloadIntervalMS);
};
/* public methods */
@ -140,8 +141,8 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings
* @param {number} interval Interval for the update in milliseconds.
*/
this.setReloadInterval = function (interval) {
if (interval > 1000 && interval < reloadInterval) {
reloadInterval = interval;
if (interval > 1000 && interval < reloadIntervalMS) {
reloadIntervalMS = interval;
}
};

View File

@ -10,12 +10,14 @@
*/
async function performWebRequest(url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) {
const request = {};
let requestUrl;
if (useCorsProxy) {
url = getCorsUrl(url, requestHeaders, expectedResponseHeaders);
requestUrl = getCorsUrl(url, requestHeaders, expectedResponseHeaders);
} else {
requestUrl = url;
request.headers = getHeadersToSend(requestHeaders);
}
const response = await fetch(url, request);
const response = await fetch(requestUrl, request);
const data = await response.text();
if (type === "xml") {

View File

@ -110,13 +110,15 @@ WeatherProvider.register("yr", {
this.getWeatherDataFromYr(weatherData?.downloadedAt)
.then((weatherData) => {
Log.debug("Got weather data from yr.");
let data;
if (weatherData) {
this.cacheWeatherData(weatherData);
data = weatherData;
} else {
//Undefined if unchanged
weatherData = this.getWeatherDataFromCache();
data = this.getWeatherDataFromCache();
}
resolve(weatherData);
resolve(data);
})
.catch((err) => {
Log.error(err);
@ -266,14 +268,14 @@ WeatherProvider.register("yr", {
this.getStellarDataFromYr(today, 2)
.then((stellarData) => {
if (stellarData) {
stellarData = {
const data = {
today: stellarData
};
stellarData.tomorrow = Object.assign({}, stellarData.today);
stellarData.today.date = today;
stellarData.tomorrow.date = tomorrow;
this.cacheStellarData(stellarData);
resolve(stellarData);
data.tomorrow = Object.assign({}, data.today);
data.today.date = today;
data.tomorrow.date = tomorrow;
this.cacheStellarData(data);
resolve(data);
} else {
Log.error(`Something went wrong when fetching stellar data. Responses: ${stellarData}`);
reject(stellarData);

View File

@ -218,29 +218,30 @@ Module.register("weather", {
this.nunjucksEnvironment().addFilter(
"unit",
function (value, type, valueUnit) {
let formattedValue;
if (type === "temperature") {
value = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
formattedValue = `${this.roundValue(WeatherUtils.convertTemp(value, this.config.tempUnits))}°`;
if (this.config.degreeLabel) {
if (this.config.tempUnits === "metric") {
value += "C";
formattedValue += "C";
} else if (this.config.tempUnits === "imperial") {
value += "F";
formattedValue += "F";
} else {
value += "K";
formattedValue += "K";
}
}
} else if (type === "precip") {
if (value === null || isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
value = "";
formattedValue = "";
} else {
value = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
formattedValue = WeatherUtils.convertPrecipitationUnit(value, valueUnit, this.config.units);
}
} else if (type === "humidity") {
value += "%";
formattedValue = `${value}%`;
} else if (type === "wind") {
value = WeatherUtils.convertWind(value, this.config.windUnits);
formattedValue = WeatherUtils.convertWind(value, this.config.windUnits);
}
return value;
return formattedValue;
}.bind(this)
);

View File

@ -154,17 +154,17 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) {
* @returns {object} The new weather provider
*/
WeatherProvider.initialize = function (providerIdentifier, delegate) {
providerIdentifier = providerIdentifier.toLowerCase();
const pi = providerIdentifier.toLowerCase();
const provider = new WeatherProvider.providers[providerIdentifier]();
const provider = new WeatherProvider.providers[pi]();
const config = Object.assign({}, provider.defaults, delegate.config);
provider.delegate = delegate;
provider.setConfig(config);
provider.providerIdentifier = providerIdentifier;
provider.providerIdentifier = pi;
if (!provider.providerName) {
provider.providerName = providerIdentifier;
provider.providerName = pi;
}
return provider;

View File

@ -32,17 +32,19 @@ const WeatherUtils = {
* @returns {string} - A string with tha value and a unit postfix.
*/
convertPrecipitationUnit(value, valueUnit, outputUnit) {
let convertedValue = value;
let conversionUnit = valueUnit;
if (outputUnit === "imperial") {
if (valueUnit && valueUnit.toLowerCase() === "cm") value = value * 0.3937007874;
else value = value * 0.03937007874;
valueUnit = "in";
if (valueUnit && valueUnit.toLowerCase() === "cm") convertedValue = convertedValue * 0.3937007874;
else convertedValue = convertedValue * 0.03937007874;
conversionUnit = "in";
} else {
valueUnit = valueUnit ? valueUnit : "mm";
conversionUnit = valueUnit ? valueUnit : "mm";
}
if (valueUnit === "%") return `${value.toFixed(0)} ${valueUnit}`;
if (valueUnit === "%") return `${convertedValue.toFixed(0)} ${conversionUnit}`;
return `${value.toFixed(2)} ${valueUnit}`;
return `${convertedValue.toFixed(2)} ${conversionUnit}`;
},
/**

243
package-lock.json generated
View File

@ -12,13 +12,13 @@
"dependencies": {
"colors": "^1.4.0",
"console-stamp": "^3.1.1",
"digest-fetch": "^2.0.1",
"digest-fetch": "^2.0.3",
"envsub": "^4.1.0",
"eslint": "^8.37.0",
"eslint": "^8.38.0",
"express": "^4.18.2",
"express-ipfilter": "^1.3.1",
"feedme": "^2.0.2",
"helmet": "^6.0.1",
"helmet": "^6.1.5",
"iconv-lite": "^0.6.3",
"luxon": "^1.28.1",
"module-alias": "^2.2.2",
@ -31,19 +31,19 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsdoc": "^40.1.1",
"eslint-plugin-jsdoc": "^41.1.1",
"eslint-plugin-prettier": "^4.2.1",
"express-basic-auth": "^1.2.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jsdom": "^21.1.1",
"lodash": "^4.17.21",
"playwright": "^1.32.2",
"playwright": "^1.32.3",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"sinon": "^15.0.3",
"stylelint": "^15.4.0",
"stylelint-config-standard": "^32.0.0",
"stylelint": "^15.5.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-prettier": "^3.0.0",
"suncalc": "^1.9.0"
},
@ -51,7 +51,7 @@
"node": ">=16"
},
"optionalDependencies": {
"electron": "^24.0.0"
"electron": "^24.1.2"
}
},
"node_modules/@ampproject/remapping": {
@ -650,9 +650,9 @@
"dev": true
},
"node_modules/@csstools/css-parser-algorithms": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.1.0.tgz",
"integrity": "sha512-KP8TicdXpUyeB1NMlbHud/1l39xvLGvqNFWMpG4qC6H1zs9SadGUHe5SO92n/659sDW9aGDvm9AMru0DZkN1Bw==",
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.1.1.tgz",
"integrity": "sha512-viRnRh02AgO4mwIQb2xQNJju0i+Fh9roNgmbR5xEuG7J3TGgxjnE95HnBLgsFJOJOksvcfxOUCgODcft6Y07cA==",
"dev": true,
"engines": {
"node": "^14 || ^16 || >=18"
@ -662,13 +662,13 @@
"url": "https://opencollective.com/csstools"
},
"peerDependencies": {
"@csstools/css-tokenizer": "^2.0.0"
"@csstools/css-tokenizer": "^2.1.1"
}
},
"node_modules/@csstools/css-tokenizer": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-2.1.0.tgz",
"integrity": "sha512-dtqFyoJBHUxGi9zPZdpCKP1xk8tq6KPHJ/NY4qWXiYo6IcSGwzk3L8x2XzZbbyOyBs9xQARoGveU2AsgLj6D2A==",
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-2.1.1.tgz",
"integrity": "sha512-GbrTj2Z8MCTUv+52GE0RbFGM527xuXZ0Xa5g0Z+YN573uveS4G0qi6WNOMyz3yrFM/jaILTTwJ0+umx81EzqfA==",
"dev": true,
"engines": {
"node": "^14 || ^16 || >=18"
@ -679,9 +679,9 @@
}
},
"node_modules/@csstools/media-query-list-parser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@csstools/media-query-list-parser/-/media-query-list-parser-2.0.1.tgz",
"integrity": "sha512-X2/OuzEbjaxhzm97UJ+95GrMeT29d1Ib+Pu+paGLuRWZnWRK9sI9r3ikmKXPWGA1C4y4JEdBEFpp9jEqCvLeRA==",
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@csstools/media-query-list-parser/-/media-query-list-parser-2.0.4.tgz",
"integrity": "sha512-GyYot6jHgcSDZZ+tLSnrzkR7aJhF2ZW6d+CXH66mjy5WpAQhZD4HDke2OQ36SivGRWlZJpAz7TzbW6OKlEpxAA==",
"dev": true,
"engines": {
"node": "^14 || ^16 || >=18"
@ -691,8 +691,8 @@
"url": "https://opencollective.com/csstools"
},
"peerDependencies": {
"@csstools/css-parser-algorithms": "^2.0.0",
"@csstools/css-tokenizer": "^2.0.0"
"@csstools/css-parser-algorithms": "^2.1.1",
"@csstools/css-tokenizer": "^2.1.1"
}
},
"node_modules/@csstools/selector-specificity": {
@ -791,9 +791,9 @@
}
},
"node_modules/@eslint/js": {
"version": "8.37.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.37.0.tgz",
"integrity": "sha512-x5vzdtOOGgFVDCUs81QRB2+liax8rFg3+7hqM+QhBG0/G3F1ZsoYl97UrqgHgQ9KKT7G6c4V+aTUCgu/n22v1A==",
"version": "8.38.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.38.0.tgz",
"integrity": "sha512-IoD2MfUnOV58ghIHCiil01PcohxjbYR/qCxsoC+xNgUwh1EY8jOOrYmu3d3a71+tJJ23uscEV4X2HJWMsPJu4g==",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
@ -1911,6 +1911,15 @@
"node": ">= 8"
}
},
"node_modules/are-docs-informative": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/are-docs-informative/-/are-docs-informative-0.0.2.tgz",
"integrity": "sha512-ixiS0nLNNG5jNQzgZJNoUpBKdo9yTYZMGJ+QgT2jmjR7G7+QHRCc4v6LQ3NgE7EBJq+o0ams3waJwkrlBom8Ig==",
"dev": true,
"engines": {
"node": ">=14"
}
},
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@ -2936,9 +2945,9 @@
}
},
"node_modules/digest-fetch": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-2.0.1.tgz",
"integrity": "sha512-OgzIWveqj8BlQ8hfJv97a9iOzWOgvI5Z3rGAnjkeNpHepHZpD/DHBDJ9mtfDclH5vkbUSGRqNEosYCH1FSO6Pg==",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-2.0.3.tgz",
"integrity": "sha512-HuTjHQE+wplAR+H8/YGwQjIGR1RQUCEsQcRyp3dZfuuxpSQH4OTm4BkHxyXuzxwmxUrNVzIPf9XkXi8QMJDNwQ==",
"dependencies": {
"base-64": "^0.1.0",
"js-sha256": "^0.9.0",
@ -2987,9 +2996,9 @@
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
},
"node_modules/electron": {
"version": "24.0.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.0.0.tgz",
"integrity": "sha512-QmL8L53fQ+xOAp8m2mSGNewhDvJqQttCxrcesf0cqndKQDsIq4QvR35wGJqHg7MyPQKcBErLhZj9QvRheO5qnA==",
"version": "24.1.2",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.1.2.tgz",
"integrity": "sha512-V0isWbyLYiXrSCcB4lrSVhS/U56NFGfuqHyc+yEPkyhhvY+h4F85cYGdEiZlXp6XjHT+/CLHmw0ltK54g9lvDw==",
"hasInstallScript": true,
"optional": true,
"dependencies": {
@ -3352,14 +3361,14 @@
}
},
"node_modules/eslint": {
"version": "8.37.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.37.0.tgz",
"integrity": "sha512-NU3Ps9nI05GUoVMxcZx1J8CNR6xOvUT4jAUMH5+z8lpp3aEdPVCImKw6PWG4PY+Vfkpr+jvMpxs/qoE7wq0sPw==",
"version": "8.38.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.38.0.tgz",
"integrity": "sha512-pIdsD2jwlUGf/U38Jv97t8lq6HpaU/G9NKbYmpWpZGw3LdTNhZLbJePqxOXGB5+JEKfOPU/XLxYxFh03nr1KTg==",
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.4.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "8.37.0",
"@eslint/js": "8.38.0",
"@humanwhocodes/config-array": "^0.11.8",
"@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8",
@ -3540,12 +3549,13 @@
}
},
"node_modules/eslint-plugin-jsdoc": {
"version": "40.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-40.1.1.tgz",
"integrity": "sha512-KxrQCq9pPt7LNeDBlLlnuJMpDFZnEQTs4e25NrT4u5cWmPw2P7F03F2qwPz0GMdlRZTyMOofuPAdiWytvPubvA==",
"version": "41.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-41.1.1.tgz",
"integrity": "sha512-dfH97DKLGtQ5dgEMzd+GSUuY+xX/yyAfjML3O0pEWmMMpylsG6Ro65s4ziYXKmixiENYK9CTQxCVRGqZUFN2Mw==",
"dev": true,
"dependencies": {
"@es-joy/jsdoccomment": "~0.37.0",
"are-docs-informative": "^0.0.2",
"comment-parser": "1.3.1",
"debug": "^4.3.4",
"escape-string-regexp": "^4.0.0",
@ -4562,9 +4572,9 @@
}
},
"node_modules/helmet": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-6.0.1.tgz",
"integrity": "sha512-8wo+VdQhTMVBMCITYZaGTbE4lvlthelPYSvoyNvk4RECTmrVjMerp9RfUOQXZWLvCcAn1pKj7ZRxK4lI9Alrcw==",
"version": "6.1.5",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-6.1.5.tgz",
"integrity": "sha512-UgAvdoG0BhF9vcCh/j0bWtElo2ZHHk6OzC98NLCM6zK03DEVSM0vUAtT7iR+oTo2Mi6sGelAH3tL6B/uUWxV4g==",
"engines": {
"node": ">=14.0.0"
}
@ -4618,9 +4628,9 @@
"dev": true
},
"node_modules/html-tags": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.2.0.tgz",
"integrity": "sha512-vy7ClnArOZwCnqZgvv+ddgHgJiAFXe3Ge9ML5/mBctVJoUoYPCdxVucOywjDARn6CVoh3dRSFdPHy2sX80L0Wg==",
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.3.1.tgz",
"integrity": "sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ==",
"dev": true,
"engines": {
"node": ">=8"
@ -6938,13 +6948,13 @@
}
},
"node_modules/playwright": {
"version": "1.32.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.32.2.tgz",
"integrity": "sha512-jHVnXJke0PXpuPszKtk9y1zZSlzO5+2a+aockT/AND0oeXx46FiJEFrafthurglLygVZA+1gEbtUM1C7qtTV+Q==",
"version": "1.32.3",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.32.3.tgz",
"integrity": "sha512-h/ylpgoj6l/EjkfUDyx8cdOlfzC96itPpPe8BXacFkqpw/YsuxkpPyVbzEq4jw+bAJh5FLgh31Ljg2cR6HV3uw==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"playwright-core": "1.32.2"
"playwright-core": "1.32.3"
},
"bin": {
"playwright": "cli.js"
@ -6954,9 +6964,9 @@
}
},
"node_modules/playwright-core": {
"version": "1.32.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.2.tgz",
"integrity": "sha512-zD7aonO+07kOTthsrCR3YCVnDcqSHIJpdFUtZEMOb6//1Rc7/6mZDRdw+nlzcQiQltOOsiqI3rrSyn/SlyjnJQ==",
"version": "1.32.3",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz",
"integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg==",
"dev": true,
"bin": {
"playwright": "cli.js"
@ -8298,14 +8308,14 @@
"dev": true
},
"node_modules/stylelint": {
"version": "15.4.0",
"resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.4.0.tgz",
"integrity": "sha512-TlOvpG3MbcFwHmK0q2ykhmpKo7Dq892beJit0NPdpyY9b1tFah/hGhqnAz/bRm2PDhDbJLKvjzkEYYBEz7Dxcg==",
"version": "15.5.0",
"resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.5.0.tgz",
"integrity": "sha512-jyMO3R1QtE5mUS4v40+Gg+sIQBqe7CF1xPslxycDzNVkIBCUD4O+5F1vLPq16VmunUTv4qG9o2rUKLnU5KkVeQ==",
"dev": true,
"dependencies": {
"@csstools/css-parser-algorithms": "^2.1.0",
"@csstools/css-tokenizer": "^2.1.0",
"@csstools/media-query-list-parser": "^2.0.1",
"@csstools/media-query-list-parser": "^2.0.2",
"@csstools/selector-specificity": "^2.2.0",
"balanced-match": "^2.0.0",
"colord": "^2.9.3",
@ -8319,7 +8329,7 @@
"global-modules": "^2.0.0",
"globby": "^11.1.0",
"globjoin": "^0.1.4",
"html-tags": "^3.2.0",
"html-tags": "^3.3.1",
"ignore": "^5.2.4",
"import-lazy": "^4.0.0",
"imurmurhash": "^0.1.4",
@ -8358,24 +8368,24 @@
}
},
"node_modules/stylelint-config-recommended": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-11.0.0.tgz",
"integrity": "sha512-SoGIHNI748OCZn6BxFYT83ytWoYETCINVHV3LKScVAWQQauWdvmdDqJC5YXWjpBbxg2E761Tg5aUGKLFOVhEkA==",
"version": "12.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-12.0.0.tgz",
"integrity": "sha512-x6x8QNARrGO2sG6iURkzqL+Dp+4bJorPMMRNPScdvaUK8PsynriOcMW7AFDKqkWAS5wbue/u8fUT/4ynzcmqdQ==",
"dev": true,
"peerDependencies": {
"stylelint": "^15.3.0"
"stylelint": "^15.5.0"
}
},
"node_modules/stylelint-config-standard": {
"version": "32.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-32.0.0.tgz",
"integrity": "sha512-UnGJxYDyYFrIE9CjDMZRkrNh2o4lOtO+MVZ9qG5b8yARfsWho0GMx4YvhHfsv8zKKgHeWX2wfeyxmuoqcaYZ4w==",
"version": "33.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-33.0.0.tgz",
"integrity": "sha512-eyxnLWoXImUn77+ODIuW9qXBDNM+ALN68L3wT1lN2oNspZ7D9NVGlNHb2QCUn4xDug6VZLsh0tF8NyoYzkgTzg==",
"dev": true,
"dependencies": {
"stylelint-config-recommended": "^11.0.0"
"stylelint-config-recommended": "^12.0.0"
},
"peerDependencies": {
"stylelint": "^15.4.0"
"stylelint": "^15.5.0"
}
},
"node_modules/stylelint-prettier": {
@ -9624,22 +9634,22 @@
"dev": true
},
"@csstools/css-parser-algorithms": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.1.0.tgz",
"integrity": "sha512-KP8TicdXpUyeB1NMlbHud/1l39xvLGvqNFWMpG4qC6H1zs9SadGUHe5SO92n/659sDW9aGDvm9AMru0DZkN1Bw==",
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-2.1.1.tgz",
"integrity": "sha512-viRnRh02AgO4mwIQb2xQNJju0i+Fh9roNgmbR5xEuG7J3TGgxjnE95HnBLgsFJOJOksvcfxOUCgODcft6Y07cA==",
"dev": true,
"requires": {}
},
"@csstools/css-tokenizer": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-2.1.0.tgz",
"integrity": "sha512-dtqFyoJBHUxGi9zPZdpCKP1xk8tq6KPHJ/NY4qWXiYo6IcSGwzk3L8x2XzZbbyOyBs9xQARoGveU2AsgLj6D2A==",
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-2.1.1.tgz",
"integrity": "sha512-GbrTj2Z8MCTUv+52GE0RbFGM527xuXZ0Xa5g0Z+YN573uveS4G0qi6WNOMyz3yrFM/jaILTTwJ0+umx81EzqfA==",
"dev": true
},
"@csstools/media-query-list-parser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@csstools/media-query-list-parser/-/media-query-list-parser-2.0.1.tgz",
"integrity": "sha512-X2/OuzEbjaxhzm97UJ+95GrMeT29d1Ib+Pu+paGLuRWZnWRK9sI9r3ikmKXPWGA1C4y4JEdBEFpp9jEqCvLeRA==",
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@csstools/media-query-list-parser/-/media-query-list-parser-2.0.4.tgz",
"integrity": "sha512-GyYot6jHgcSDZZ+tLSnrzkR7aJhF2ZW6d+CXH66mjy5WpAQhZD4HDke2OQ36SivGRWlZJpAz7TzbW6OKlEpxAA==",
"dev": true,
"requires": {}
},
@ -9707,9 +9717,9 @@
}
},
"@eslint/js": {
"version": "8.37.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.37.0.tgz",
"integrity": "sha512-x5vzdtOOGgFVDCUs81QRB2+liax8rFg3+7hqM+QhBG0/G3F1ZsoYl97UrqgHgQ9KKT7G6c4V+aTUCgu/n22v1A=="
"version": "8.38.0",
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.38.0.tgz",
"integrity": "sha512-IoD2MfUnOV58ghIHCiil01PcohxjbYR/qCxsoC+xNgUwh1EY8jOOrYmu3d3a71+tJJ23uscEV4X2HJWMsPJu4g=="
},
"@humanwhocodes/config-array": {
"version": "0.11.8",
@ -10595,6 +10605,12 @@
"picomatch": "^2.0.4"
}
},
"are-docs-informative": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/are-docs-informative/-/are-docs-informative-0.0.2.tgz",
"integrity": "sha512-ixiS0nLNNG5jNQzgZJNoUpBKdo9yTYZMGJ+QgT2jmjR7G7+QHRCc4v6LQ3NgE7EBJq+o0ams3waJwkrlBom8Ig==",
"dev": true
},
"argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@ -11336,9 +11352,9 @@
"dev": true
},
"digest-fetch": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-2.0.1.tgz",
"integrity": "sha512-OgzIWveqj8BlQ8hfJv97a9iOzWOgvI5Z3rGAnjkeNpHepHZpD/DHBDJ9mtfDclH5vkbUSGRqNEosYCH1FSO6Pg==",
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-2.0.3.tgz",
"integrity": "sha512-HuTjHQE+wplAR+H8/YGwQjIGR1RQUCEsQcRyp3dZfuuxpSQH4OTm4BkHxyXuzxwmxUrNVzIPf9XkXi8QMJDNwQ==",
"requires": {
"base-64": "^0.1.0",
"js-sha256": "^0.9.0",
@ -11378,9 +11394,9 @@
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="
},
"electron": {
"version": "24.0.0",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.0.0.tgz",
"integrity": "sha512-QmL8L53fQ+xOAp8m2mSGNewhDvJqQttCxrcesf0cqndKQDsIq4QvR35wGJqHg7MyPQKcBErLhZj9QvRheO5qnA==",
"version": "24.1.2",
"resolved": "https://registry.npmjs.org/electron/-/electron-24.1.2.tgz",
"integrity": "sha512-V0isWbyLYiXrSCcB4lrSVhS/U56NFGfuqHyc+yEPkyhhvY+h4F85cYGdEiZlXp6XjHT+/CLHmw0ltK54g9lvDw==",
"optional": true,
"requires": {
"@electron/get": "^2.0.0",
@ -11649,14 +11665,14 @@
}
},
"eslint": {
"version": "8.37.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.37.0.tgz",
"integrity": "sha512-NU3Ps9nI05GUoVMxcZx1J8CNR6xOvUT4jAUMH5+z8lpp3aEdPVCImKw6PWG4PY+Vfkpr+jvMpxs/qoE7wq0sPw==",
"version": "8.38.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.38.0.tgz",
"integrity": "sha512-pIdsD2jwlUGf/U38Jv97t8lq6HpaU/G9NKbYmpWpZGw3LdTNhZLbJePqxOXGB5+JEKfOPU/XLxYxFh03nr1KTg==",
"requires": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.4.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "8.37.0",
"@eslint/js": "8.38.0",
"@humanwhocodes/config-array": "^0.11.8",
"@humanwhocodes/module-importer": "^1.0.1",
"@nodelib/fs.walk": "^1.2.8",
@ -11797,12 +11813,13 @@
}
},
"eslint-plugin-jsdoc": {
"version": "40.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-40.1.1.tgz",
"integrity": "sha512-KxrQCq9pPt7LNeDBlLlnuJMpDFZnEQTs4e25NrT4u5cWmPw2P7F03F2qwPz0GMdlRZTyMOofuPAdiWytvPubvA==",
"version": "41.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-41.1.1.tgz",
"integrity": "sha512-dfH97DKLGtQ5dgEMzd+GSUuY+xX/yyAfjML3O0pEWmMMpylsG6Ro65s4ziYXKmixiENYK9CTQxCVRGqZUFN2Mw==",
"dev": true,
"requires": {
"@es-joy/jsdoccomment": "~0.37.0",
"are-docs-informative": "^0.0.2",
"comment-parser": "1.3.1",
"debug": "^4.3.4",
"escape-string-regexp": "^4.0.0",
@ -12543,9 +12560,9 @@
}
},
"helmet": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-6.0.1.tgz",
"integrity": "sha512-8wo+VdQhTMVBMCITYZaGTbE4lvlthelPYSvoyNvk4RECTmrVjMerp9RfUOQXZWLvCcAn1pKj7ZRxK4lI9Alrcw=="
"version": "6.1.5",
"resolved": "https://registry.npmjs.org/helmet/-/helmet-6.1.5.tgz",
"integrity": "sha512-UgAvdoG0BhF9vcCh/j0bWtElo2ZHHk6OzC98NLCM6zK03DEVSM0vUAtT7iR+oTo2Mi6sGelAH3tL6B/uUWxV4g=="
},
"hosted-git-info": {
"version": "4.1.0",
@ -12589,9 +12606,9 @@
"dev": true
},
"html-tags": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.2.0.tgz",
"integrity": "sha512-vy7ClnArOZwCnqZgvv+ddgHgJiAFXe3Ge9ML5/mBctVJoUoYPCdxVucOywjDARn6CVoh3dRSFdPHy2sX80L0Wg==",
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.3.1.tgz",
"integrity": "sha512-ztqyC3kLto0e9WbNp0aeP+M3kTt+nbaIveGmUxAtZa+8iFgKLUOD4YKM5j+f3QD89bra7UeumolZHKuOXnTmeQ==",
"dev": true
},
"http-cache-semantics": {
@ -14308,18 +14325,18 @@
}
},
"playwright": {
"version": "1.32.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.32.2.tgz",
"integrity": "sha512-jHVnXJke0PXpuPszKtk9y1zZSlzO5+2a+aockT/AND0oeXx46FiJEFrafthurglLygVZA+1gEbtUM1C7qtTV+Q==",
"version": "1.32.3",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.32.3.tgz",
"integrity": "sha512-h/ylpgoj6l/EjkfUDyx8cdOlfzC96itPpPe8BXacFkqpw/YsuxkpPyVbzEq4jw+bAJh5FLgh31Ljg2cR6HV3uw==",
"dev": true,
"requires": {
"playwright-core": "1.32.2"
"playwright-core": "1.32.3"
}
},
"playwright-core": {
"version": "1.32.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.2.tgz",
"integrity": "sha512-zD7aonO+07kOTthsrCR3YCVnDcqSHIJpdFUtZEMOb6//1Rc7/6mZDRdw+nlzcQiQltOOsiqI3rrSyn/SlyjnJQ==",
"version": "1.32.3",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz",
"integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg==",
"dev": true
},
"postcss": {
@ -15293,14 +15310,14 @@
"dev": true
},
"stylelint": {
"version": "15.4.0",
"resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.4.0.tgz",
"integrity": "sha512-TlOvpG3MbcFwHmK0q2ykhmpKo7Dq892beJit0NPdpyY9b1tFah/hGhqnAz/bRm2PDhDbJLKvjzkEYYBEz7Dxcg==",
"version": "15.5.0",
"resolved": "https://registry.npmjs.org/stylelint/-/stylelint-15.5.0.tgz",
"integrity": "sha512-jyMO3R1QtE5mUS4v40+Gg+sIQBqe7CF1xPslxycDzNVkIBCUD4O+5F1vLPq16VmunUTv4qG9o2rUKLnU5KkVeQ==",
"dev": true,
"requires": {
"@csstools/css-parser-algorithms": "^2.1.0",
"@csstools/css-tokenizer": "^2.1.0",
"@csstools/media-query-list-parser": "^2.0.1",
"@csstools/media-query-list-parser": "^2.0.2",
"@csstools/selector-specificity": "^2.2.0",
"balanced-match": "^2.0.0",
"colord": "^2.9.3",
@ -15314,7 +15331,7 @@
"global-modules": "^2.0.0",
"globby": "^11.1.0",
"globjoin": "^0.1.4",
"html-tags": "^3.2.0",
"html-tags": "^3.3.1",
"ignore": "^5.2.4",
"import-lazy": "^4.0.0",
"imurmurhash": "^0.1.4",
@ -15367,19 +15384,19 @@
}
},
"stylelint-config-recommended": {
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-11.0.0.tgz",
"integrity": "sha512-SoGIHNI748OCZn6BxFYT83ytWoYETCINVHV3LKScVAWQQauWdvmdDqJC5YXWjpBbxg2E761Tg5aUGKLFOVhEkA==",
"version": "12.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-recommended/-/stylelint-config-recommended-12.0.0.tgz",
"integrity": "sha512-x6x8QNARrGO2sG6iURkzqL+Dp+4bJorPMMRNPScdvaUK8PsynriOcMW7AFDKqkWAS5wbue/u8fUT/4ynzcmqdQ==",
"dev": true,
"requires": {}
},
"stylelint-config-standard": {
"version": "32.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-32.0.0.tgz",
"integrity": "sha512-UnGJxYDyYFrIE9CjDMZRkrNh2o4lOtO+MVZ9qG5b8yARfsWho0GMx4YvhHfsv8zKKgHeWX2wfeyxmuoqcaYZ4w==",
"version": "33.0.0",
"resolved": "https://registry.npmjs.org/stylelint-config-standard/-/stylelint-config-standard-33.0.0.tgz",
"integrity": "sha512-eyxnLWoXImUn77+ODIuW9qXBDNM+ALN68L3wT1lN2oNspZ7D9NVGlNHb2QCUn4xDug6VZLsh0tF8NyoYzkgTzg==",
"dev": true,
"requires": {
"stylelint-config-recommended": "^11.0.0"
"stylelint-config-recommended": "^12.0.0"
}
},
"stylelint-prettier": {

View File

@ -52,35 +52,35 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsdoc": "^40.1.1",
"eslint-plugin-jsdoc": "^41.1.1",
"eslint-plugin-prettier": "^4.2.1",
"express-basic-auth": "^1.2.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jsdom": "^21.1.1",
"lodash": "^4.17.21",
"playwright": "^1.32.2",
"playwright": "^1.32.3",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"sinon": "^15.0.3",
"stylelint": "^15.4.0",
"stylelint-config-standard": "^32.0.0",
"stylelint": "^15.5.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-prettier": "^3.0.0",
"suncalc": "^1.9.0"
},
"optionalDependencies": {
"electron": "^24.0.0"
"electron": "^24.1.2"
},
"dependencies": {
"colors": "^1.4.0",
"console-stamp": "^3.1.1",
"digest-fetch": "^2.0.1",
"digest-fetch": "^2.0.3",
"envsub": "^4.1.0",
"eslint": "^8.37.0",
"eslint": "^8.38.0",
"express": "^4.18.2",
"express-ipfilter": "^1.3.1",
"feedme": "^2.0.2",
"helmet": "^6.0.1",
"helmet": "^6.1.5",
"iconv-lite": "^0.6.3",
"luxon": "^1.28.1",
"module-alias": "^2.2.2",

View File

@ -4,21 +4,19 @@ const { performWebRequest, formatTime } = require("../../../../modules/default/u
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
describe("Default modules utils tests", () => {
describe("The performWebRequest-method", () => {
describe("performWebRequest", () => {
if (nodeVersion > 18) {
const locationHost = "localhost:8080";
const locationProtocol = "http";
let fetchResponse;
let fetchMock;
let url;
let urlToCall;
beforeEach(() => {
fetchResponse = new Response();
global.fetch = jest.fn(() => Promise.resolve(fetchResponse));
fetchMock = global.fetch;
url = "www.test.com";
});
describe("When using cors proxy", () => {
@ -30,24 +28,23 @@ describe("Default modules utils tests", () => {
});
test("Calls correct URL once", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
await performWebRequest(url, "json", true);
await performWebRequest(urlToCall, "json", true);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?url=${urlToCall}`);
});
test("Sends correct headers", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
const headers = [
{ name: "header1", value: "value1" },
{ name: "header2", value: "value2" }
];
await performWebRequest(url, "json", true, headers);
await performWebRequest(urlToCall, "json", true, headers);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?sendheaders=header1:value1,header2:value2&url=${urlToCall}`);
@ -56,24 +53,22 @@ describe("Default modules utils tests", () => {
describe("When not using cors proxy", () => {
test("Calls correct URL once", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
await performWebRequest(url);
await performWebRequest(urlToCall);
expect(fetchMock.mock.calls.length).toBe(1);
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
});
test("Sends correct headers", async () => {
const urlToCall = "http://www.test.com/path?param1=value1";
url = urlToCall;
urlToCall = "http://www.test.com/path?param1=value1";
const headers = [
{ name: "header1", value: "value1" },
{ name: "header2", value: "value2" }
];
await performWebRequest(url, "json", false, headers);
await performWebRequest(urlToCall, "json", false, headers);
const expectedHeaders = { headers: { header1: "value1", header2: "value2" } };
expect(fetchMock.mock.calls.length).toBe(1);
@ -83,23 +78,27 @@ describe("Default modules utils tests", () => {
describe("When receiving json format", () => {
test("Returns undefined when no data is received", async () => {
const response = await performWebRequest(url);
urlToCall = "www.test.com";
const response = await performWebRequest(urlToCall);
expect(response).toBe(undefined);
});
test("Returns object when data is received", async () => {
urlToCall = "www.test.com";
fetchResponse = new Response('{"body": "some content"}');
const response = await performWebRequest(url);
const response = await performWebRequest(urlToCall);
expect(response.body).toBe("some content");
});
test("Returns expected headers when data is received", async () => {
urlToCall = "www.test.com";
fetchResponse = new Response('{"body": "some content"}', { headers: { header1: "value1", header2: "value2" } });
const response = await performWebRequest(url, "json", false, undefined, ["header1"]);
const response = await performWebRequest(urlToCall, "json", false, undefined, ["header1"]);
expect(response.headers.length).toBe(1);
expect(response.headers[0].name).toBe("header1");