diff --git a/package.json b/package.json index f39b914db..ba7560758 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "eslint-plugin-tsdoc": "^0.3.0", "eslint-plugin-unicorn": "^53.0.0", "fake-indexeddb": "^5.0.2", - "fetch-mock": "9.11.0", + "fetch-mock": "10.0.7", "fetch-mock-jest": "^1.5.1", "husky": "^9.0.0", "jest": "^29.0.0", diff --git a/spec/integ/crypto/crypto.spec.ts b/spec/integ/crypto/crypto.spec.ts index fd3b2778c..2f1342a54 100644 --- a/spec/integ/crypto/crypto.spec.ts +++ b/spec/integ/crypto/crypto.spec.ts @@ -19,7 +19,7 @@ import anotherjson from "another-json"; import fetchMock from "fetch-mock-jest"; import "fake-indexeddb/auto"; import { IDBFactory } from "fake-indexeddb"; -import { MockResponse, MockResponseFunction } from "fetch-mock"; +import FetchMock from "fetch-mock"; import Olm from "@matrix-org/olm"; import * as testUtils from "../../test-utils/test-utils"; @@ -157,7 +157,7 @@ async function expectSendRoomKey( return await new Promise((resolve) => { fetchMock.putOnce( new RegExp("/sendToDevice/m.room.encrypted/"), - (url: string, opts: RequestInit): MockResponse => { + (url: string, opts: RequestInit): FetchMock.MockResponse => { const content = JSON.parse(opts.body as string); resolve(onSendRoomKey(content)); return {}; @@ -291,7 +291,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, * @param response - the response to return from the request. Normally an {@link IClaimOTKsResult} * (or a function that returns one). */ - function expectAliceKeyClaim(response: MockResponse | MockResponseFunction) { + function expectAliceKeyClaim(response: FetchMock.MockResponse | FetchMock.MockResponseFunction) { const rootRegexp = escapeRegExp(new URL("/_matrix/client/", aliceClient.getHomeserverUrl()).toString()); fetchMock.postOnce(new RegExp(rootRegexp + "(r0|v3)/keys/claim"), response); } @@ -1419,7 +1419,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, fetchMock.putOnce( { url: new RegExp("/send/"), name: "send-event" }, - (url: string, opts: RequestInit): MockResponse => { + (url: string, opts: RequestInit): FetchMock.MockResponse => { const content = JSON.parse(opts.body as string); logger.log("/send:", content); // make sure that a new session is used @@ -1484,7 +1484,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, // mark the device as known, and resend. aliceClient.setDeviceKnown(aliceClient.getUserId()!, "DEVICE_ID"); - expectAliceKeyClaim((url: string, opts: RequestInit): MockResponse => { + expectAliceKeyClaim((url: string, opts: RequestInit): FetchMock.MockResponse => { const content = JSON.parse(opts.body as string); expect(content.one_time_keys[aliceClient.getUserId()!].DEVICE_ID).toEqual("signed_curve25519"); return getTestKeysClaimResponse(aliceClient.getUserId()!); @@ -2180,11 +2180,11 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, const inboundGroupSessionPromise = expectSendRoomKey("@bob:xyz", testOlmAccount); // ... and finally, send the room key. We block the response until `sendRoomMessageDefer` completes. - const sendRoomMessageDefer = defer(); + const sendRoomMessageDefer = defer(); const reqProm = new Promise((resolve) => { fetchMock.putOnce( new RegExp("/send/m.room.encrypted/"), - async (url: string, opts: RequestInit): Promise => { + async (url: string, opts: RequestInit): Promise => { resolve(JSON.parse(opts.body as string)); return await sendRoomMessageDefer.promise; }, diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index ae9ebcd59..d288adfa0 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -17,7 +17,7 @@ limitations under the License. import "fake-indexeddb/auto"; import anotherjson from "another-json"; -import { MockResponse } from "fetch-mock"; +import FetchMock from "fetch-mock"; import fetchMock from "fetch-mock-jest"; import { IDBFactory } from "fake-indexeddb"; import { createHash } from "crypto"; @@ -1511,7 +1511,7 @@ function expectSendToDeviceMessage(msgtype: string): Promise<{ messages: any }> return new Promise((resolve) => { fetchMock.putOnce( new RegExp(`/_matrix/client/(r0|v3)/sendToDevice/${escapeRegExp(msgtype)}`), - (url: string, opts: RequestInit): MockResponse => { + (url: string, opts: RequestInit): FetchMock.MockResponse => { resolve(JSON.parse(opts.body as string)); return {}; }, @@ -1535,7 +1535,7 @@ function mockSecretRequestAndGetPromises(): Map> { fetchMock.put( new RegExp(`/_matrix/client/(r0|v3)/sendToDevice/m.secret.request`), - (url: string, opts: RequestInit): MockResponse => { + (url: string, opts: RequestInit): FetchMock.MockResponse => { const messages = JSON.parse(opts.body as string).messages[TEST_USER_ID]; // rust crypto broadcasts to all devices, old crypto to a specific device, take the first one const content = Object.values(messages)[0] as any; diff --git a/spec/test-utils/AccountDataAccumulator.ts b/spec/test-utils/AccountDataAccumulator.ts index dca35bc2c..f24b7f53b 100644 --- a/spec/test-utils/AccountDataAccumulator.ts +++ b/spec/test-utils/AccountDataAccumulator.ts @@ -15,7 +15,6 @@ limitations under the License. */ import fetchMock from "fetch-mock-jest"; -import { MockOptionsMethodPut } from "fetch-mock"; import { ISyncResponder } from "./SyncResponder"; @@ -40,7 +39,10 @@ export class AccountDataAccumulator { * @param opts - options to pass to fetchMock * @returns a Promise which will resolve (with the content of the account data) once it is set. */ - public interceptSetAccountData(accountDataType: string, opts?: MockOptionsMethodPut): Promise { + public interceptSetAccountData( + accountDataType: string, + opts?: Parameters<(typeof fetchMock)["put"]>[2], + ): Promise { return new Promise((resolve) => { // Called when the cross signing key is uploaded fetchMock.put( diff --git a/spec/test-utils/SyncResponder.ts b/spec/test-utils/SyncResponder.ts index 31fae7147..3caba9dfa 100644 --- a/spec/test-utils/SyncResponder.ts +++ b/spec/test-utils/SyncResponder.ts @@ -17,7 +17,7 @@ limitations under the License. import debugFunc from "debug"; import { Debugger } from "debug"; import fetchMock from "fetch-mock-jest"; -import { MockResponse } from "fetch-mock"; +import FetchMock from "fetch-mock"; /** Interface implemented by classes that intercept `/sync` requests from test clients * @@ -80,7 +80,7 @@ export class SyncResponder implements ISyncResponder { ); } - private async onSyncRequest(): Promise { + private async onSyncRequest(): Promise { switch (this.state) { case SyncResponderState.IDLE: { this.debug("Got /sync request: waiting for response to be ready"); diff --git a/yarn.lock b/yarn.lock index cd365cb19..685a1c3cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3663,7 +3663,19 @@ fetch-mock-jest@^1.5.1: dependencies: fetch-mock "^9.11.0" -fetch-mock@9.11.0, fetch-mock@^9.11.0: +fetch-mock@10.0.7: + version "10.0.7" + resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-10.0.7.tgz#b274aaebe5b59c641f02d836b579bbe9b063f8db" + integrity sha512-TFG42kMRJ6dZpUDeVTdXNjh5O4TchHU/UNk41a050TwKzRr5RJQbtckXDjXiQFHPKgXGUG5l2TY3ZZ2gokiXaQ== + dependencies: + debug "^4.1.1" + glob-to-regexp "^0.4.0" + is-subset "^0.1.1" + lodash.isequal "^4.5.0" + path-to-regexp "^2.2.1" + querystring "^0.2.1" + +fetch-mock@^9.11.0: version "9.11.0" resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-9.11.0.tgz#371c6fb7d45584d2ae4a18ee6824e7ad4b637a3f" integrity sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q== @@ -5680,7 +5692,7 @@ pvutils@^1.1.3: resolved "https://registry.yarnpkg.com/pvutils/-/pvutils-1.1.3.tgz#f35fc1d27e7cd3dfbd39c0826d173e806a03f5a3" integrity sha512-pMpnA0qRdFp32b1sJl1wOJNxZLQ2cbQx+k6tjNtZ8CpvVhNqEPRgivZ2WOUev2YMajecdH7ctUPDvEe87nariQ== -querystring@^0.2.0: +querystring@^0.2.0, querystring@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd" integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==