From 19038a42cd973e66a3daff987f8c651d6924b6ae Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 30 Oct 2024 19:09:01 +0000 Subject: [PATCH] Prefer native node fetch over node-fetch Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 2 -- test/setup/setupManualMocks.ts | 4 ---- test/unit-tests/vector/getconfig-test.ts | 9 ++++++--- yarn.lock | 8 -------- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 11232c479c..762e3d8739 100644 --- a/package.json +++ b/package.json @@ -203,7 +203,6 @@ "@types/minimist": "^1.2.5", "@types/modernizr": "^3.5.3", "@types/node": "18", - "@types/node-fetch": "^2.6.2", "@types/pako": "^2.0.0", "@types/qrcode": "^1.3.5", "@types/react": "18.3.3", @@ -268,7 +267,6 @@ "mkdirp": "^3.0.0", "mocha-junit-reporter": "^2.2.0", "modernizr": "^3.12.0", - "node-fetch": "^2.6.7", "playwright-core": "^1.45.1", "postcss": "8.4.38", "postcss-easings": "^4.0.0", diff --git a/test/setup/setupManualMocks.ts b/test/setup/setupManualMocks.ts index 8064048baa..0cc34a6918 100644 --- a/test/setup/setupManualMocks.ts +++ b/test/setup/setupManualMocks.ts @@ -8,7 +8,6 @@ Please see LICENSE files in the repository root for full details. import fetchMock from "fetch-mock-jest"; import { TextDecoder, TextEncoder } from "util"; -import { Response } from "node-fetch"; import { mocks } from "./mocks"; @@ -80,8 +79,5 @@ fetchMock.get("/_matrix/client/versions", {}); // @ts-ignore window.fetch = fetchMock.sandbox(); -// @ts-ignore -window.Response = Response; - // set up AudioContext API mock global.AudioContext = jest.fn().mockImplementation(() => ({ ...mocks.AudioContext })); diff --git a/test/unit-tests/vector/getconfig-test.ts b/test/unit-tests/vector/getconfig-test.ts index cba19d5ae6..5a2e9388e3 100644 --- a/test/unit-tests/vector/getconfig-test.ts +++ b/test/unit-tests/vector/getconfig-test.ts @@ -98,8 +98,11 @@ describe("getVectorConfig()", () => { fetchMock.getOnce("express:/config.app.element.io.json", { throws: "err-specific" }); fetchMock.getOnce("express:/config.json", '{"invalid": "json",}'); - // We can't assert it'll be a SyntaxError as node-fetch behaves differently - // https://github.com/wheresrhys/fetch-mock/issues/270 - await expect(getVectorConfig()).rejects.toThrow("in JSON at position 19"); + await expect(getVectorConfig()).rejects.toThrow( + new SyntaxError( + "invalid json response body at https://app.element.io/config.json?cachebuster=1234567890 reason: " + + "Expected double-quoted property name in JSON at position 19 (line 1 column 20)", + ), + ); }); }); diff --git a/yarn.lock b/yarn.lock index dee966cb86..385740f796 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3012,14 +3012,6 @@ resolved "https://registry.yarnpkg.com/@types/modernizr/-/modernizr-3.5.6.tgz#c50d64a73edc30284679f09ad54e7d095e69f2a0" integrity sha512-yslwR0zZ3zAT1qXcCPxIcD23CZ6W6nKsl6JufSJHAmdwOBuYwCVJkaMsEo9yzxGV7ATfoX8S+RgtnajOEtKxYA== -"@types/node-fetch@^2.6.2": - version "2.6.11" - resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.11.tgz#9b39b78665dae0e82a08f02f4967d62c66f95d24" - integrity sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g== - dependencies: - "@types/node" "*" - form-data "^4.0.0" - "@types/node-forge@^1.3.0": version "1.3.11" resolved "https://registry.yarnpkg.com/@types/node-forge/-/node-forge-1.3.11.tgz#0972ea538ddb0f4d9c2fa0ec5db5724773a604da"