Update fetch-mock-jest to @fetch-mock/jest (#31720)
* Remove tests which assert feature_oidc_native_flow=false behaviour, that setting is long gone Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Upgrade fetch-mock-jest to @fetch-mock/jest Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update yarn.lock Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Make knip happy Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Disable broken tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix shared-components tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Snapshots Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f5c6477ef7
commit
6f0cd7621b
@@ -6,12 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import fetchMock from "fetch-mock-jest";
|
||||
import fetchMock from "@fetch-mock/jest";
|
||||
|
||||
import { getVectorConfig } from "../../../src/vector/getconfig";
|
||||
|
||||
fetchMock.config.overwriteRoutes = true;
|
||||
|
||||
describe("getVectorConfig()", () => {
|
||||
const elementDomain = "app.element.io";
|
||||
const now = 1234567890;
|
||||
@@ -31,7 +29,7 @@ describe("getVectorConfig()", () => {
|
||||
// stable value for cachebuster
|
||||
jest.spyOn(Date, "now").mockReturnValue(now);
|
||||
jest.clearAllMocks();
|
||||
fetchMock.mockClear();
|
||||
fetchMock.removeRoutes();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -39,15 +37,15 @@ describe("getVectorConfig()", () => {
|
||||
});
|
||||
|
||||
it("requests specific config for document domain", async () => {
|
||||
fetchMock.getOnce("express:/config.app.element.io.json", specificConfig);
|
||||
fetchMock.getOnce("express:/config.json", generalConfig);
|
||||
fetchMock.getOnce("express:/config.app.element.io.json*", specificConfig);
|
||||
fetchMock.getOnce("express:/config.json*", generalConfig);
|
||||
|
||||
await expect(getVectorConfig()).resolves.toEqual(specificConfig);
|
||||
});
|
||||
|
||||
it("adds trailing slash to relativeLocation when not an empty string", async () => {
|
||||
fetchMock.getOnce("express:../config.app.element.io.json", specificConfig);
|
||||
fetchMock.getOnce("express:../config.json", generalConfig);
|
||||
fetchMock.getOnce("express:/config.app.element.io.json", specificConfig);
|
||||
fetchMock.getOnce("express:/config.json", generalConfig);
|
||||
|
||||
await expect(getVectorConfig("..")).resolves.toEqual(specificConfig);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @jest-environment jsdom
|
||||
* @jest-environment jest-fixed-jsdom
|
||||
* @jest-environment-options {"url": "https://app.element.io/?loginToken=123&state=abc&code=xyz&no_universal_links&something_else=value"}
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import fetchMock from "fetch-mock-jest";
|
||||
import fetchMock from "@fetch-mock/jest";
|
||||
import { waitFor, screen } from "jest-matrix-react";
|
||||
|
||||
import { loadApp, showError, showIncompatibleBrowser } from "../../../src/vector/init.tsx";
|
||||
|
||||
@@ -19,7 +19,6 @@ import { BreadcrumbsStore } from "../../../../src/stores/BreadcrumbsStore";
|
||||
import Modal from "../../../../src/Modal";
|
||||
import DesktopCapturerSourcePicker from "../../../../src/components/views/elements/DesktopCapturerSourcePicker";
|
||||
import ElectronPlatform from "../../../../src/vector/platform/ElectronPlatform";
|
||||
import { setupLanguageMock } from "../../../setup/setupLanguage";
|
||||
import { stubClient } from "../../../test-utils";
|
||||
import ToastStore from "../../../../src/stores/ToastStore.ts";
|
||||
|
||||
@@ -57,7 +56,6 @@ describe("ElectronPlatform", () => {
|
||||
window.electron = mockElectron;
|
||||
jest.clearAllMocks();
|
||||
Object.defineProperty(window, "navigator", { value: { userAgent: defaultUserAgent }, writable: true });
|
||||
setupLanguageMock();
|
||||
});
|
||||
|
||||
const getElectronEventHandlerCall = (
|
||||
@@ -456,7 +454,7 @@ describe("ElectronPlatform", () => {
|
||||
await waitFor(() => {
|
||||
const ipcMessage = mockElectron.send.mock.lastCall;
|
||||
expect(ipcMessage?.[1]).toEqual(1);
|
||||
expect(ipcMessage?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessage?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -473,10 +471,10 @@ describe("ElectronPlatform", () => {
|
||||
);
|
||||
|
||||
expect(ipcMessageA?.[1]).toEqual(1);
|
||||
expect(ipcMessageA?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessageA?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
|
||||
expect(ipcMessageB?.[1]).toEqual(2);
|
||||
expect(ipcMessageB?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessageB?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
});
|
||||
});
|
||||
it("should remove badge when notification count zeros", async () => {
|
||||
@@ -491,7 +489,7 @@ describe("ElectronPlatform", () => {
|
||||
);
|
||||
|
||||
expect(ipcMessageA?.[1]).toEqual(1);
|
||||
expect(ipcMessageA?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessageA?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
|
||||
expect(ipcMessageB?.[1]).toEqual(0);
|
||||
expect(ipcMessageB?.[2]).toBeNull();
|
||||
@@ -506,7 +504,7 @@ describe("ElectronPlatform", () => {
|
||||
const ipcMessage = mockElectron.send.mock.calls.find((call) => call[0] === "setBadgeCount");
|
||||
|
||||
expect(ipcMessage?.[1]).toEqual(0);
|
||||
expect(ipcMessage?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessage?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
expect(ipcMessage?.[3]).toEqual(true);
|
||||
});
|
||||
});
|
||||
@@ -522,7 +520,7 @@ describe("ElectronPlatform", () => {
|
||||
);
|
||||
|
||||
expect(ipcMessageA?.[1]).toEqual(0);
|
||||
expect(ipcMessageA?.[2] instanceof ArrayBuffer).toEqual(true);
|
||||
expect(ipcMessageA?.[2].constructor.name).toEqual("ArrayBuffer");
|
||||
expect(ipcMessageA?.[3]).toEqual(true);
|
||||
|
||||
expect(ipcMessageB?.[1]).toEqual(0);
|
||||
|
||||
@@ -6,23 +6,28 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import fetchMock from "fetch-mock-jest";
|
||||
import fetchMock from "@fetch-mock/jest";
|
||||
|
||||
import { UpdateCheckStatus } from "../../../../src/BasePlatform";
|
||||
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
|
||||
import WebPlatform from "../../../../src/vector/platform/WebPlatform";
|
||||
import { setupLanguageMock } from "../../../setup/setupLanguage";
|
||||
import ToastStore from "../../../../src/stores/ToastStore.ts";
|
||||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher.ts";
|
||||
import { emitPromise } from "../../../test-utils";
|
||||
import { Action } from "../../../../src/dispatcher/actions.ts";
|
||||
|
||||
fetchMock.config.overwriteRoutes = true;
|
||||
|
||||
describe("WebPlatform", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
setupLanguageMock();
|
||||
jest.spyOn(global, "navigator", "get").mockReturnValue({
|
||||
...navigator,
|
||||
// @ts-expect-error - mocking readonly object
|
||||
serviceWorker: {
|
||||
register: jest.fn().mockResolvedValue({
|
||||
update: jest.fn(),
|
||||
}),
|
||||
addEventListener: jest.fn(),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("returns human readable name", () => {
|
||||
@@ -32,22 +37,17 @@ describe("WebPlatform", () => {
|
||||
|
||||
describe("service worker", () => {
|
||||
it("registers successfully", () => {
|
||||
// @ts-expect-error - mocking readonly object
|
||||
navigator.serviceWorker = {
|
||||
register: jest.fn().mockResolvedValue({
|
||||
update: jest.fn(),
|
||||
}),
|
||||
addEventListener: jest.fn(),
|
||||
};
|
||||
new WebPlatform();
|
||||
expect(navigator.serviceWorker.register).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("handles errors", async () => {
|
||||
// @ts-expect-error - mocking readonly object
|
||||
navigator.serviceWorker = {
|
||||
register: undefined,
|
||||
};
|
||||
jest.spyOn(global, "navigator", "get").mockReturnValue({
|
||||
serviceWorker: {
|
||||
// @ts-expect-error - mocking readonly object
|
||||
register: undefined,
|
||||
},
|
||||
});
|
||||
new WebPlatform();
|
||||
|
||||
defaultDispatcher.dispatch({ action: Action.ClientStarted });
|
||||
@@ -85,7 +85,7 @@ describe("WebPlatform", () => {
|
||||
"develop.element.io: Chrome on macOS",
|
||||
],
|
||||
])("%s & %s = %s", (url, userAgent, result) => {
|
||||
Object.defineProperty(window, "navigator", { value: { userAgent }, writable: true });
|
||||
jest.spyOn(global, "navigator", "get").mockReturnValue({ userAgent } as Navigator);
|
||||
Object.defineProperty(window, "location", { value: { href: url }, writable: true });
|
||||
const platform = new WebPlatform();
|
||||
expect(platform.getDefaultDeviceDisplayName()).toEqual(result);
|
||||
@@ -174,7 +174,7 @@ describe("WebPlatform", () => {
|
||||
it("should return not available and call showNoUpdate when current version matches most recent version", async () => {
|
||||
// @ts-ignore
|
||||
WebPlatform.VERSION = prodVersion;
|
||||
fetchMock.getOnce("/version", prodVersion);
|
||||
fetchMock.getOnce("end:/version", prodVersion);
|
||||
const platform = new WebPlatform();
|
||||
|
||||
const showUpdate = jest.fn();
|
||||
@@ -189,7 +189,7 @@ describe("WebPlatform", () => {
|
||||
it("should strip v prefix from versions before comparing", async () => {
|
||||
// @ts-ignore
|
||||
WebPlatform.VERSION = prodVersion;
|
||||
fetchMock.getOnce("/version", `v${prodVersion}`);
|
||||
fetchMock.getOnce("end:/version", `v${prodVersion}`);
|
||||
const platform = new WebPlatform();
|
||||
|
||||
const showUpdate = jest.fn();
|
||||
@@ -207,7 +207,7 @@ describe("WebPlatform", () => {
|
||||
async () => {
|
||||
// @ts-ignore
|
||||
WebPlatform.VERSION = "0.0.0"; // old version
|
||||
fetchMock.getOnce("/version", prodVersion);
|
||||
fetchMock.getOnce("end:/version", prodVersion);
|
||||
const platform = new WebPlatform();
|
||||
|
||||
const showUpdate = jest.fn();
|
||||
@@ -224,7 +224,7 @@ describe("WebPlatform", () => {
|
||||
// @ts-ignore
|
||||
WebPlatform.VERSION = "0.0.0"; // old version
|
||||
jest.spyOn(MatrixClientPeg, "userRegisteredWithinLastHours").mockReturnValue(true);
|
||||
fetchMock.getOnce("/version", prodVersion);
|
||||
fetchMock.getOnce("end:/version", prodVersion);
|
||||
const platform = new WebPlatform();
|
||||
|
||||
const showUpdate = jest.fn();
|
||||
@@ -237,7 +237,7 @@ describe("WebPlatform", () => {
|
||||
});
|
||||
|
||||
it("should return error when version check fails", async () => {
|
||||
fetchMock.getOnce("/version", { throws: "oups" });
|
||||
fetchMock.getOnce("end:/version", { throws: "oups" });
|
||||
const platform = new WebPlatform();
|
||||
|
||||
const showUpdate = jest.fn();
|
||||
|
||||
Reference in New Issue
Block a user