mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Minimum node version v18 (#3170)
When the next MagicMirror version is released, node v16 will have reached its end of life.
This commit is contained in:
parent
7dcea98e99
commit
7c64d8fce6
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@ -43,7 +43,7 @@ When submitting a new issue, please supply the following information:
|
|||||||
|
|
||||||
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
||||||
|
|
||||||
**Node Version**: Make sure it's version 16 or later (recommended is 18).
|
**Node Version**: Make sure it's version 18 or later (recommended is 20).
|
||||||
|
|
||||||
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
||||||
|
|
||||||
|
2
.github/ISSUE_TEMPLATE/custom.md
vendored
2
.github/ISSUE_TEMPLATE/custom.md
vendored
@ -35,7 +35,7 @@ When submitting a new issue, please supply the following information:
|
|||||||
|
|
||||||
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
**Platform**: Place your platform here... give us your web browser/Electron version _and_ your hardware (Raspberry Pi 2/3/4, Windows, Mac, Linux, System V UNIX).
|
||||||
|
|
||||||
**Node Version**: Make sure it's version 16 or later (recommended is 18).
|
**Node Version**: Make sure it's version 18 or later (recommended is 20).
|
||||||
|
|
||||||
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
**MagicMirror² Version**: Please let us know which version of MagicMirror² you are running. It can be found in the `package.json` file.
|
||||||
|
|
||||||
|
2
.github/workflows/automated-tests.yaml
vendored
2
.github/workflows/automated-tests.yaml
vendored
@ -18,7 +18,7 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [16.x, 18.x, 20.x]
|
node-version: [18.x, 20.x]
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout code"
|
- name: "Checkout code"
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
@ -21,6 +21,7 @@ _This release is scheduled to be released on 2023-10-01._
|
|||||||
- Update issue template
|
- Update issue template
|
||||||
- Update dependencies incl. electron to v26
|
- Update dependencies incl. electron to v26
|
||||||
- Replace pretty-quick by lint-staged (<https://github.com/azz/pretty-quick/issues/164>)
|
- Replace pretty-quick by lint-staged (<https://github.com/azz/pretty-quick/issues/164>)
|
||||||
|
- Minimum node version is now v18. v16 reached it's end of life.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
11
js/fetch.js
11
js/fetch.js
@ -11,15 +11,8 @@
|
|||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
async function fetch(url, options = {}) {
|
async function fetch(url, options = {}) {
|
||||||
// const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
// return global.fetch(url, options);
|
||||||
// if (nodeVersion >= 18) {
|
|
||||||
// // node version >= 18
|
|
||||||
// return global.fetch(url, options);
|
|
||||||
// } else {
|
|
||||||
// // node version < 18
|
|
||||||
// const nodefetch = require("node-fetch");
|
|
||||||
// return nodefetch(url, options);
|
|
||||||
// }
|
|
||||||
const nodefetch = require("node-fetch");
|
const nodefetch = require("node-fetch");
|
||||||
return nodefetch(url, options);
|
return nodefetch(url, options);
|
||||||
}
|
}
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -48,7 +48,7 @@
|
|||||||
"suncalc": "^1.9.0"
|
"suncalc": "^1.9.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"electron": "^26.0.0"
|
"electron": "^26.0.0"
|
||||||
|
@ -100,6 +100,6 @@
|
|||||||
"fetch": "js/fetch.js"
|
"fetch": "js/fetch.js"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,113 +1,107 @@
|
|||||||
global.moment = require("moment-timezone");
|
global.moment = require("moment-timezone");
|
||||||
const { performWebRequest, formatTime } = require("../../../../modules/default/utils");
|
const { performWebRequest, formatTime } = require("../../../../modules/default/utils");
|
||||||
|
|
||||||
const nodeVersion = process.version.match(/^v(\d+)\.*/)[1];
|
|
||||||
|
|
||||||
describe("Default modules utils tests", () => {
|
describe("Default modules utils tests", () => {
|
||||||
describe("performWebRequest", () => {
|
describe("performWebRequest", () => {
|
||||||
if (nodeVersion > 18) {
|
const locationHost = "localhost:8080";
|
||||||
const locationHost = "localhost:8080";
|
const locationProtocol = "http";
|
||||||
const locationProtocol = "http";
|
|
||||||
|
|
||||||
let fetchResponse;
|
let fetchResponse;
|
||||||
let fetchMock;
|
let fetchMock;
|
||||||
let urlToCall;
|
let urlToCall;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fetchResponse = new Response();
|
fetchResponse = new Response();
|
||||||
global.fetch = jest.fn(() => Promise.resolve(fetchResponse));
|
global.fetch = jest.fn(() => Promise.resolve(fetchResponse));
|
||||||
fetchMock = global.fetch;
|
fetchMock = global.fetch;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("When using cors proxy", () => {
|
||||||
|
Object.defineProperty(global, "location", {
|
||||||
|
value: {
|
||||||
|
host: locationHost,
|
||||||
|
protocol: locationProtocol
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("When using cors proxy", () => {
|
test("Calls correct URL once", async () => {
|
||||||
Object.defineProperty(global, "location", {
|
urlToCall = "http://www.test.com/path?param1=value1";
|
||||||
value: {
|
|
||||||
host: locationHost,
|
|
||||||
protocol: locationProtocol
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Calls correct URL once", async () => {
|
await performWebRequest(urlToCall, "json", true);
|
||||||
urlToCall = "http://www.test.com/path?param1=value1";
|
|
||||||
|
|
||||||
await performWebRequest(urlToCall, "json", true);
|
expect(fetchMock.mock.calls.length).toBe(1);
|
||||||
|
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?url=${urlToCall}`);
|
||||||
expect(fetchMock.mock.calls.length).toBe(1);
|
|
||||||
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?url=${urlToCall}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Sends correct headers", async () => {
|
|
||||||
urlToCall = "http://www.test.com/path?param1=value1";
|
|
||||||
|
|
||||||
const headers = [
|
|
||||||
{ name: "header1", value: "value1" },
|
|
||||||
{ name: "header2", value: "value2" }
|
|
||||||
];
|
|
||||||
|
|
||||||
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}`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("When not using cors proxy", () => {
|
test("Sends correct headers", async () => {
|
||||||
test("Calls correct URL once", async () => {
|
urlToCall = "http://www.test.com/path?param1=value1";
|
||||||
urlToCall = "http://www.test.com/path?param1=value1";
|
|
||||||
|
|
||||||
await performWebRequest(urlToCall);
|
const headers = [
|
||||||
|
{ name: "header1", value: "value1" },
|
||||||
|
{ name: "header2", value: "value2" }
|
||||||
|
];
|
||||||
|
|
||||||
expect(fetchMock.mock.calls.length).toBe(1);
|
await performWebRequest(urlToCall, "json", true, headers);
|
||||||
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Sends correct headers", async () => {
|
expect(fetchMock.mock.calls.length).toBe(1);
|
||||||
urlToCall = "http://www.test.com/path?param1=value1";
|
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?sendheaders=header1:value1,header2:value2&url=${urlToCall}`);
|
||||||
const headers = [
|
});
|
||||||
{ name: "header1", value: "value1" },
|
});
|
||||||
{ name: "header2", value: "value2" }
|
|
||||||
];
|
|
||||||
|
|
||||||
await performWebRequest(urlToCall, "json", false, headers);
|
describe("When not using cors proxy", () => {
|
||||||
|
test("Calls correct URL once", async () => {
|
||||||
|
urlToCall = "http://www.test.com/path?param1=value1";
|
||||||
|
|
||||||
const expectedHeaders = { headers: { header1: "value1", header2: "value2" } };
|
await performWebRequest(urlToCall);
|
||||||
expect(fetchMock.mock.calls.length).toBe(1);
|
|
||||||
expect(fetchMock.mock.calls[0][1]).toStrictEqual(expectedHeaders);
|
expect(fetchMock.mock.calls.length).toBe(1);
|
||||||
});
|
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("When receiving json format", () => {
|
test("Sends correct headers", async () => {
|
||||||
test("Returns undefined when no data is received", async () => {
|
urlToCall = "http://www.test.com/path?param1=value1";
|
||||||
urlToCall = "www.test.com";
|
const headers = [
|
||||||
|
{ name: "header1", value: "value1" },
|
||||||
|
{ name: "header2", value: "value2" }
|
||||||
|
];
|
||||||
|
|
||||||
const response = await performWebRequest(urlToCall);
|
await performWebRequest(urlToCall, "json", false, headers);
|
||||||
|
|
||||||
expect(response).toBe(undefined);
|
const expectedHeaders = { headers: { header1: "value1", header2: "value2" } };
|
||||||
});
|
expect(fetchMock.mock.calls.length).toBe(1);
|
||||||
|
expect(fetchMock.mock.calls[0][1]).toStrictEqual(expectedHeaders);
|
||||||
test("Returns object when data is received", async () => {
|
|
||||||
urlToCall = "www.test.com";
|
|
||||||
fetchResponse = new Response('{"body": "some content"}');
|
|
||||||
|
|
||||||
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(urlToCall, "json", false, undefined, ["header1"]);
|
|
||||||
|
|
||||||
expect(response.headers.length).toBe(1);
|
|
||||||
expect(response.headers[0].name).toBe("header1");
|
|
||||||
expect(response.headers[0].value).toBe("value1");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
test("Always ok, need one test", () => {});
|
|
||||||
}
|
describe("When receiving json format", () => {
|
||||||
|
test("Returns undefined when no data is received", async () => {
|
||||||
|
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(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(urlToCall, "json", false, undefined, ["header1"]);
|
||||||
|
|
||||||
|
expect(response.headers.length).toBe(1);
|
||||||
|
expect(response.headers[0].name).toBe("header1");
|
||||||
|
expect(response.headers[0].value).toBe("value1");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("formatTime", () => {
|
describe("formatTime", () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user