use internal fetch as replacement for node-fetch (#3184)

related to #2649

I was able to move to internal fetch and all tests seems fine so far.

But we have one problem with the calendar module. In the docs we have
several authentication methods and one of them is `digest`. For this we
used `digest-fetch` which needs `node-fetch` (this is not so clear from
code but I was not able to get it working).

So we have 3 options:
- remove `digest` as authentication method for calendar module (this is
what this PR does at the moment)
- find an alternative npm package or implement the digest stuff
ourselves
- use `digest-fetch` and `node-fetch` for calendar module (so they would
remain as dependencies in `package.json`)

Opinions? @KristjanESPERANTO @rejas @sdetweil @MichMich
This commit is contained in:
Karsten Hassel
2023-09-09 21:12:31 +02:00
committed by GitHub
parent ffdf321e23
commit f2957f90df
16 changed files with 24 additions and 115 deletions

View File

@@ -10,12 +10,12 @@ describe("App environment", () => {
});
it("get request from http://localhost:8080 should return 200", async () => {
const res = await helpers.fetch("http://localhost:8080");
const res = await fetch("http://localhost:8080");
expect(res.status).toBe(200);
});
it("get request from http://localhost:8080/nothing should return 404", async () => {
const res = await helpers.fetch("http://localhost:8080/nothing");
const res = await fetch("http://localhost:8080/nothing");
expect(res.status).toBe(404);
});

View File

@@ -22,7 +22,7 @@ describe("All font files from roboto.css should be downloadable", () => {
test.each(fontFiles)("should return 200 HTTP code for file '%s'", async (fontFile) => {
const fontUrl = `http://localhost:8080/fonts/${fontFile}`;
const res = await helpers.fetch(fontUrl);
const res = await fetch(fontUrl);
expect(res.status).toBe(200);
});
});

View File

@@ -1,5 +1,4 @@
const jsdom = require("jsdom");
const corefetch = require("fetch");
exports.startApplication = async (configFilename, exec) => {
jest.resetModules();
@@ -31,7 +30,7 @@ exports.getDocument = () => {
const url = `http://${config.address || "localhost"}:${config.port || "8080"}`;
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
dom.window.name = "jsdom";
dom.window.fetch = corefetch;
dom.window.fetch = fetch;
dom.window.onload = () => {
global.document = dom.window.document;
resolve();
@@ -80,14 +79,6 @@ exports.waitForAllElements = (selector) => {
});
};
exports.fetch = (url) => {
return new Promise((resolve) => {
corefetch(url).then((res) => {
resolve(res);
});
});
};
exports.testMatch = async (element, regex) => {
const elem = await this.waitForElement(element);
expect(elem).not.toBe(null);

View File

@@ -10,7 +10,7 @@ describe("ipWhitelist directive configuration", () => {
});
it("should return 403", async () => {
const res = await helpers.fetch("http://localhost:8181");
const res = await fetch("http://localhost:8181");
expect(res.status).toBe(403);
});
});
@@ -24,7 +24,7 @@ describe("ipWhitelist directive configuration", () => {
});
it("should return 200", async () => {
const res = await helpers.fetch("http://localhost:8282");
const res = await fetch("http://localhost:8282");
expect(res.status).toBe(200);
});
});

View File

@@ -10,7 +10,7 @@ describe("port directive configuration", () => {
});
it("should return 200", async () => {
const res = await helpers.fetch("http://localhost:8090");
const res = await fetch("http://localhost:8090");
expect(res.status).toBe(200);
});
});
@@ -24,7 +24,7 @@ describe("port directive configuration", () => {
});
it("should return 200", async () => {
const res = await helpers.fetch("http://localhost:8100");
const res = await fetch("http://localhost:8100");
expect(res.status).toBe(200);
});
});

View File

@@ -17,12 +17,12 @@ describe("App environment", () => {
});
it("get request from http://localhost:8080 should return 200", async () => {
const res = await helpers.fetch("http://localhost:8080");
const res = await fetch("http://localhost:8080");
expect(res.status).toBe(200);
});
it("get request from http://localhost:8080/nothing should return 404", async () => {
const res = await helpers.fetch("http://localhost:8080/nothing");
const res = await fetch("http://localhost:8080/nothing");
expect(res.status).toBe(404);
});
});

View File

@@ -9,7 +9,7 @@ describe("templated config with port variable", () => {
});
it("should return 200", async () => {
const res = await helpers.fetch("http://localhost:8090");
const res = await fetch("http://localhost:8090");
expect(res.status).toBe(200);
});
});

View File

@@ -14,7 +14,7 @@ describe("Vendors", () => {
Object.keys(vendors).forEach((vendor) => {
it(`should return 200 HTTP code for vendor "${vendor}"`, async () => {
const urlVendor = `http://localhost:8080/vendor/${vendors[vendor]}`;
const res = await helpers.fetch(urlVendor);
const res = await fetch(urlVendor);
expect(res.status).toBe(200);
});
});
@@ -22,7 +22,7 @@ describe("Vendors", () => {
Object.keys(vendors).forEach((vendor) => {
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, async () => {
const urlVendor = `http://localhost:8080/${vendors[vendor]}`;
const res = await helpers.fetch(urlVendor);
const res = await fetch(urlVendor);
expect(res.status).toBe(404);
});
});