diff --git a/CHANGELOG.md b/CHANGELOG.md index dd7fafe1..5e606bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ Special thanks to: @rejas, @sdetweil ### Removed +- Removed usage of internal fetch function of node until it is more stable. + ### Updated - Cleaned up test directory (#2937) and jest config (#2959) diff --git a/js/fetch.js b/js/fetch.js index 8009dc16..3ae874c8 100644 --- a/js/fetch.js +++ b/js/fetch.js @@ -1,20 +1,28 @@ /** - * fetch + * Helper class to provide either third party fetch library or (if node >= 18) + * return internal node fetch implementation. * + * Attention: After some discussion we always return the third party + * implementation until the node implementation is stable and more tested + * + * @see https://github.com/MichMich/MagicMirror/pull/2952 + * @see https://github.com/MichMich/MagicMirror/issues/2649 * @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); - } + // 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); + // } + const nodefetch = require("node-fetch"); + return nodefetch(url, options); } module.exports = fetch; diff --git a/tests/e2e/helpers/global-setup.js b/tests/e2e/helpers/global-setup.js index 7f60b40e..ee8fb83e 100644 --- a/tests/e2e/helpers/global-setup.js +++ b/tests/e2e/helpers/global-setup.js @@ -1,4 +1,5 @@ const jsdom = require("jsdom"); +const corefetch = require("fetch"); exports.startApplication = async (configFilename, exec) => { jest.resetModules(); @@ -82,8 +83,13 @@ exports.waitForAllElements = (selector) => { }); }; -// When native fetch is used keep-alive is set which causes issues with tests that should not share the connection, fall back to use the older one for now... -exports.fetch = require("node-fetch"); +exports.fetch = (url) => { + return new Promise((resolve) => { + corefetch(url).then((res) => { + resolve(res); + }); + }); +}; exports.testMatch = async (element, regex) => { const elem = await this.waitForElement(element);