mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
use internal fetch function of node instead external node-fetch
library if node version >= v18
This commit is contained in:
parent
cbda20f67e
commit
0023c64d59
@ -19,6 +19,7 @@ _This release is scheduled to be released on 2022-07-01._
|
|||||||
|
|
||||||
- Use latest node 18 when running tests on github actions
|
- Use latest node 18 when running tests on github actions
|
||||||
- Update `electron` to v18 and other dependencies.
|
- Update `electron` to v18 and other dependencies.
|
||||||
|
- Use internal fetch function of node instead external `node-fetch` library if node version >= `v18`.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
20
js/fetch.js
Normal file
20
js/fetch.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* fetch
|
||||||
|
*
|
||||||
|
* @param {string} url to be fetched
|
||||||
|
* @param {object} options object e.g. for headers
|
||||||
|
* @class
|
||||||
|
*/
|
||||||
|
async function fetch(url, options) {
|
||||||
|
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
||||||
|
if (nodeVersion >= 18) {
|
||||||
|
// node version >= 18
|
||||||
|
return global.fetch(url, options);
|
||||||
|
} else {
|
||||||
|
// node version < 18
|
||||||
|
const nodefetch = require("node-fetch");
|
||||||
|
return nodefetch(url, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = fetch;
|
@ -10,7 +10,7 @@ const path = require("path");
|
|||||||
const ipfilter = require("express-ipfilter").IpFilter;
|
const ipfilter = require("express-ipfilter").IpFilter;
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const helmet = require("helmet");
|
const helmet = require("helmet");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
|
|
||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const Utils = require("./utils.js");
|
const Utils = require("./utils.js");
|
||||||
|
@ -8,7 +8,7 @@ const CalendarUtils = require("./calendarutils");
|
|||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const ical = require("node-ical");
|
const ical = require("node-ical");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const digest = require("digest-fetch");
|
const digest = require("digest-fetch");
|
||||||
const https = require("https");
|
const https = require("https");
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
const Log = require("logger");
|
const Log = require("logger");
|
||||||
const FeedMe = require("feedme");
|
const FeedMe = require("feedme");
|
||||||
const NodeHelper = require("node_helper");
|
const NodeHelper = require("node_helper");
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const iconv = require("iconv-lite");
|
const iconv = require("iconv-lite");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,7 +89,8 @@
|
|||||||
},
|
},
|
||||||
"_moduleAliases": {
|
"_moduleAliases": {
|
||||||
"node_helper": "js/node_helper.js",
|
"node_helper": "js/node_helper.js",
|
||||||
"logger": "js/logger.js"
|
"logger": "js/logger.js",
|
||||||
|
"fetch": "js/fetch.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const helpers = require("./global-setup");
|
const helpers = require("./global-setup");
|
||||||
|
|
||||||
describe("App environment", function () {
|
describe("App environment", function () {
|
||||||
@ -6,8 +6,8 @@ describe("App environment", function () {
|
|||||||
helpers.startApplication("tests/configs/default.js");
|
helpers.startApplication("tests/configs/default.js");
|
||||||
helpers.getDocument(done);
|
helpers.getDocument(done);
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("get request from http://localhost:8080 should return 200", function (done) {
|
it("get request from http://localhost:8080 should return 200", function (done) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const helpers = require("./global-setup");
|
const helpers = require("./global-setup");
|
||||||
|
|
||||||
describe("All font files from roboto.css should be downloadable", function () {
|
describe("All font files from roboto.css should be downloadable", function () {
|
||||||
@ -17,8 +17,8 @@ describe("All font files from roboto.css should be downloadable", function () {
|
|||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/without_modules.js");
|
helpers.startApplication("tests/configs/without_modules.js");
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
|
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
|
||||||
|
@ -16,10 +16,11 @@ exports.startApplication = function (configFilename, exec) {
|
|||||||
global.app.start();
|
global.app.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.stopApplication = function () {
|
exports.stopApplication = async function () {
|
||||||
if (global.app) {
|
if (global.app) {
|
||||||
global.app.stop();
|
global.app.stop();
|
||||||
}
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getDocument = function (callback) {
|
exports.getDocument = function (callback) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const helpers = require("./global-setup");
|
const helpers = require("./global-setup");
|
||||||
|
|
||||||
describe("ipWhitelist directive configuration", function () {
|
describe("ipWhitelist directive configuration", function () {
|
||||||
@ -6,8 +6,8 @@ describe("ipWhitelist directive configuration", function () {
|
|||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/noIpWhiteList.js");
|
helpers.startApplication("tests/configs/noIpWhiteList.js");
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 403", function (done) {
|
it("should return 403", function (done) {
|
||||||
@ -22,8 +22,8 @@ describe("ipWhitelist directive configuration", function () {
|
|||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
|
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 200", function (done) {
|
it("should return 200", function (done) {
|
||||||
|
@ -5,8 +5,8 @@ describe("Alert module", function () {
|
|||||||
helpers.startApplication("tests/configs/modules/alert/default.js");
|
helpers.startApplication("tests/configs/modules/alert/default.js");
|
||||||
helpers.getDocument(done);
|
helpers.getDocument(done);
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the welcome message", function () {
|
it("should show the welcome message", function () {
|
||||||
|
@ -25,8 +25,8 @@ describe("Calendar module", function () {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Default configuration", function () {
|
describe("Default configuration", function () {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
const helpers = require("../global-setup");
|
const helpers = require("../global-setup");
|
||||||
|
|
||||||
describe("Clock set to spanish language module", function () {
|
describe("Clock set to spanish language module", function () {
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
const testMatch = function (element, regex) {
|
const testMatch = function (element, regex) {
|
||||||
|
@ -2,8 +2,8 @@ const helpers = require("../global-setup");
|
|||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
|
|
||||||
describe("Clock module", function () {
|
describe("Clock module", function () {
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
const testMatch = function (element, regex) {
|
const testMatch = function (element, regex) {
|
||||||
|
@ -16,8 +16,8 @@ function doTest(complimentsArray) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("Compliments module", function () {
|
describe("Compliments module", function () {
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("parts of days", function () {
|
describe("parts of days", function () {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
const helpers = require("../global-setup");
|
const helpers = require("../global-setup");
|
||||||
|
|
||||||
describe("Test helloworld module", function () {
|
describe("Test helloworld module", function () {
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("helloworld set config text", function () {
|
describe("helloworld set config text", function () {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
const helpers = require("../global-setup");
|
const helpers = require("../global-setup");
|
||||||
|
|
||||||
describe("Newsfeed module", function () {
|
describe("Newsfeed module", function () {
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Default configuration", function () {
|
describe("Default configuration", function () {
|
||||||
|
@ -40,8 +40,8 @@ describe("Weather module", function () {
|
|||||||
helpers.getDocument(callback);
|
helpers.getDocument(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Current weather", function () {
|
describe("Current weather", function () {
|
||||||
|
@ -5,8 +5,8 @@ describe("Display of modules", function () {
|
|||||||
helpers.startApplication("tests/configs/modules/display.js");
|
helpers.startApplication("tests/configs/modules/display.js");
|
||||||
helpers.getDocument(done);
|
helpers.getDocument(done);
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should show the test header", function () {
|
it("should show the test header", function () {
|
||||||
|
@ -5,8 +5,8 @@ describe("Position of modules", function () {
|
|||||||
helpers.startApplication("tests/configs/modules/positions.js");
|
helpers.startApplication("tests/configs/modules/positions.js");
|
||||||
helpers.getDocument(done);
|
helpers.getDocument(done);
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const helpers = require("./global-setup");
|
const helpers = require("./global-setup");
|
||||||
|
|
||||||
describe("port directive configuration", function () {
|
describe("port directive configuration", function () {
|
||||||
@ -6,8 +6,8 @@ describe("port directive configuration", function () {
|
|||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/port_8090.js");
|
helpers.startApplication("tests/configs/port_8090.js");
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 200", function (done) {
|
it("should return 200", function (done) {
|
||||||
@ -22,8 +22,8 @@ describe("port directive configuration", function () {
|
|||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
|
helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return 200", function (done) {
|
it("should return 200", function (done) {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const fetch = require("node-fetch");
|
const fetch = require("fetch");
|
||||||
const helpers = require("./global-setup");
|
const helpers = require("./global-setup");
|
||||||
|
|
||||||
describe("Vendors", function () {
|
describe("Vendors", function () {
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
helpers.startApplication("tests/configs/default.js");
|
helpers.startApplication("tests/configs/default.js");
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Get list vendors", function () {
|
describe("Get list vendors", function () {
|
||||||
|
@ -5,8 +5,8 @@ describe("Check configuration without modules", function () {
|
|||||||
helpers.startApplication("tests/configs/without_modules.js");
|
helpers.startApplication("tests/configs/without_modules.js");
|
||||||
helpers.getDocument(done);
|
helpers.getDocument(done);
|
||||||
});
|
});
|
||||||
afterAll(function () {
|
afterAll(async function () {
|
||||||
helpers.stopApplication();
|
await helpers.stopApplication();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Show the message MagicMirror² title", function () {
|
it("Show the message MagicMirror² title", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user