Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 8b54be6

Browse files
authored
Move from browser-request to fetch (#9345)
1 parent ae883bb commit 8b54be6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1464
-597
lines changed

__mocks__/browser-request.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

cypress/e2e/spotlight/spotlight.spec.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ Cypress.Commands.add("startDM", (name: string) => {
124124
cy.get(".mx_BasicMessageComposer_input")
125125
.should("have.focus")
126126
.type("Hey!{enter}");
127-
cy.contains(".mx_EventTile_body", "Hey!");
127+
// The DM room is created at this point, this can take a little bit of time
128+
cy.contains(".mx_EventTile_body", "Hey!", { timeout: 30000 });
128129
cy.contains(".mx_RoomSublist[aria-label=People]", name);
129130
});
130131

@@ -217,7 +218,7 @@ describe("Spotlight", () => {
217218
it("should find joined rooms", () => {
218219
cy.openSpotlightDialog().within(() => {
219220
cy.spotlightSearch().clear().type(room1Name);
220-
cy.wait(1000); // wait for the dialog code to settle
221+
cy.wait(3000); // wait for the dialog code to settle
221222
cy.spotlightResults().should("have.length", 1);
222223
cy.spotlightResults().eq(0).should("contain", room1Name);
223224
cy.spotlightResults().eq(0).click();
@@ -231,7 +232,7 @@ describe("Spotlight", () => {
231232
cy.openSpotlightDialog().within(() => {
232233
cy.spotlightFilter(Filter.PublicRooms);
233234
cy.spotlightSearch().clear().type(room1Name);
234-
cy.wait(1000); // wait for the dialog code to settle
235+
cy.wait(3000); // wait for the dialog code to settle
235236
cy.spotlightResults().should("have.length", 1);
236237
cy.spotlightResults().eq(0).should("contain", room1Name);
237238
cy.spotlightResults().eq(0).should("contain", "View");
@@ -246,7 +247,7 @@ describe("Spotlight", () => {
246247
cy.openSpotlightDialog().within(() => {
247248
cy.spotlightFilter(Filter.PublicRooms);
248249
cy.spotlightSearch().clear().type(room2Name);
249-
cy.wait(1000); // wait for the dialog code to settle
250+
cy.wait(3000); // wait for the dialog code to settle
250251
cy.spotlightResults().should("have.length", 1);
251252
cy.spotlightResults().eq(0).should("contain", room2Name);
252253
cy.spotlightResults().eq(0).should("contain", "Join");
@@ -262,7 +263,7 @@ describe("Spotlight", () => {
262263
cy.openSpotlightDialog().within(() => {
263264
cy.spotlightFilter(Filter.PublicRooms);
264265
cy.spotlightSearch().clear().type(room3Name);
265-
cy.wait(1000); // wait for the dialog code to settle
266+
cy.wait(3000); // wait for the dialog code to settle
266267
cy.spotlightResults().should("have.length", 1);
267268
cy.spotlightResults().eq(0).should("contain", room3Name);
268269
cy.spotlightResults().eq(0).should("contain", "View");
@@ -301,7 +302,7 @@ describe("Spotlight", () => {
301302
cy.openSpotlightDialog().within(() => {
302303
cy.spotlightFilter(Filter.People);
303304
cy.spotlightSearch().clear().type(bot1Name);
304-
cy.wait(1000); // wait for the dialog code to settle
305+
cy.wait(3000); // wait for the dialog code to settle
305306
cy.spotlightResults().should("have.length", 1);
306307
cy.spotlightResults().eq(0).should("contain", bot1Name);
307308
cy.spotlightResults().eq(0).click();
@@ -314,7 +315,7 @@ describe("Spotlight", () => {
314315
cy.openSpotlightDialog().within(() => {
315316
cy.spotlightFilter(Filter.People);
316317
cy.spotlightSearch().clear().type(bot2Name);
317-
cy.wait(1000); // wait for the dialog code to settle
318+
cy.wait(3000); // wait for the dialog code to settle
318319
cy.spotlightResults().should("have.length", 1);
319320
cy.spotlightResults().eq(0).should("contain", bot2Name);
320321
cy.spotlightResults().eq(0).click();
@@ -331,7 +332,7 @@ describe("Spotlight", () => {
331332
cy.openSpotlightDialog().within(() => {
332333
cy.spotlightFilter(Filter.People);
333334
cy.spotlightSearch().clear().type(bot2Name);
334-
cy.wait(1000); // wait for the dialog code to settle
335+
cy.wait(3000); // wait for the dialog code to settle
335336
cy.spotlightResults().should("have.length", 1);
336337
cy.spotlightResults().eq(0).should("contain", bot2Name);
337338
cy.spotlightResults().eq(0).click();
@@ -345,7 +346,7 @@ describe("Spotlight", () => {
345346
.type("Hey!{enter}");
346347

347348
// Assert DM exists by checking for the first message and the room being in the room list
348-
cy.contains(".mx_EventTile_body", "Hey!");
349+
cy.contains(".mx_EventTile_body", "Hey!", { timeout: 30000 });
349350
cy.get(".mx_RoomSublist[aria-label=People]").should("contain", bot2Name);
350351

351352
// Invite BotBob into existing DM with ByteBot
@@ -409,7 +410,7 @@ describe("Spotlight", () => {
409410
cy.openSpotlightDialog().within(() => {
410411
cy.spotlightFilter(Filter.People);
411412
cy.spotlightSearch().clear().type(bot2Name);
412-
cy.wait(1000); // wait for the dialog code to settle
413+
cy.wait(3000); // wait for the dialog code to settle
413414
cy.spotlightResults().should("have.length", 1);
414415
cy.spotlightResults().eq(0).should("contain", bot2Name);
415416
cy.get(".mx_SpotlightDialog_startGroupChat").should("contain", "Start a group chat");
@@ -431,7 +432,7 @@ describe("Spotlight", () => {
431432
cy.openSpotlightDialog().within(() => {
432433
cy.spotlightFilter(Filter.People);
433434
cy.spotlightSearch().clear().type(bot1Name);
434-
cy.wait(1000); // wait for the dialog code to settle
435+
cy.wait(3000); // wait for the dialog code to settle
435436
cy.get(".mx_Spinner").should("not.exist");
436437
cy.spotlightResults().should("have.length", 1);
437438
});

cypress/e2e/timeline/timeline.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ describe("Timeline", () => {
9191

9292
describe("useOnlyCurrentProfiles", () => {
9393
beforeEach(() => {
94-
cy.uploadContent(OLD_AVATAR).then((url) => {
94+
cy.uploadContent(OLD_AVATAR).then(({ content_uri: url }) => {
9595
oldAvatarUrl = url;
9696
cy.setAvatarUrl(url);
9797
});
98-
cy.uploadContent(NEW_AVATAR).then((url) => {
98+
cy.uploadContent(NEW_AVATAR).then(({ content_uri: url }) => {
9999
newAvatarUrl = url;
100100
});
101101
});
@@ -271,7 +271,7 @@ describe("Timeline", () => {
271271
cy.get(".mx_RoomHeader_searchButton").click();
272272
cy.get(".mx_SearchBar_input input").type("Message{enter}");
273273

274-
cy.get(".mx_EventTile:not(.mx_EventTile_contextual)").find(".mx_EventTile_searchHighlight").should("exist");
274+
cy.get(".mx_EventTile:not(.mx_EventTile_contextual) .mx_EventTile_searchHighlight").should("exist");
275275
cy.get(".mx_RoomView_searchResultsPanel").percySnapshotElement("Highlighted search results");
276276
});
277277

cypress/support/bot.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ limitations under the License.
1616

1717
/// <reference types="cypress" />
1818

19-
import request from "browser-request";
20-
2119
import type { ISendEventResponse, MatrixClient, Room } from "matrix-js-sdk/src/matrix";
2220
import { SynapseInstance } from "../plugins/synapsedocker";
2321
import Chainable = Cypress.Chainable;
@@ -86,7 +84,6 @@ Cypress.Commands.add("getBot", (synapse: SynapseInstance, opts: CreateBotOpts):
8684
userId: credentials.userId,
8785
deviceId: credentials.deviceId,
8886
accessToken: credentials.accessToken,
89-
request,
9087
store: new win.matrixcs.MemoryStore(),
9188
scheduler: new win.matrixcs.MatrixScheduler(),
9289
cryptoStore: new win.matrixcs.MemoryCryptoStore(),

cypress/support/client.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ limitations under the License.
1616

1717
/// <reference types="cypress" />
1818

19-
import type { FileType, UploadContentResponseType } from "matrix-js-sdk/src/http-api";
20-
import type { IAbortablePromise } from "matrix-js-sdk/src/@types/partials";
21-
import type { ICreateRoomOpts, ISendEventResponse, IUploadOpts } from "matrix-js-sdk/src/@types/requests";
19+
import type { FileType, Upload, UploadOpts } from "matrix-js-sdk/src/http-api";
20+
import type { ICreateRoomOpts, ISendEventResponse } from "matrix-js-sdk/src/@types/requests";
2221
import type { MatrixClient } from "matrix-js-sdk/src/client";
2322
import type { Room } from "matrix-js-sdk/src/models/room";
2423
import type { IContent } from "matrix-js-sdk/src/models/event";
@@ -90,10 +89,10 @@ declare global {
9089
* can be sent to XMLHttpRequest.send (typically a File). Under node.js,
9190
* a a Buffer, String or ReadStream.
9291
*/
93-
uploadContent<O extends IUploadOpts>(
92+
uploadContent(
9493
file: FileType,
95-
opts?: O,
96-
): IAbortablePromise<UploadContentResponseType<O>>;
94+
opts?: UploadOpts,
95+
): Chainable<Awaited<Upload["promise"]>>;
9796
/**
9897
* Turn an MXC URL into an HTTP one. <strong>This method is experimental and
9998
* may change.</strong>
@@ -203,9 +202,9 @@ Cypress.Commands.add("setDisplayName", (name: string): Chainable<{}> => {
203202
});
204203
});
205204

206-
Cypress.Commands.add("uploadContent", (file: FileType): Chainable<{}> => {
205+
Cypress.Commands.add("uploadContent", (file: FileType, opts?: UploadOpts): Chainable<Awaited<Upload["promise"]>> => {
207206
return cy.getClient().then(async (cli: MatrixClient) => {
208-
return cli.uploadContent(file);
207+
return cli.uploadContent(file, opts);
209208
});
210209
});
211210

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
"@types/ua-parser-js": "^0.7.36",
6666
"await-lock": "^2.1.0",
6767
"blurhash": "^1.1.3",
68-
"browser-request": "^0.3.3",
6968
"cheerio": "^1.0.0-rc.9",
7069
"classnames": "^2.2.6",
7170
"commonmark": "^0.29.3",
@@ -190,16 +189,16 @@
190189
"eslint-plugin-matrix-org": "^0.6.1",
191190
"eslint-plugin-react": "^7.28.0",
192191
"eslint-plugin-react-hooks": "^4.3.0",
192+
"fetch-mock-jest": "^1.5.1",
193193
"fs-extra": "^10.0.1",
194194
"glob": "^7.1.6",
195195
"jest": "^27.4.0",
196196
"jest-canvas-mock": "^2.3.0",
197197
"jest-environment-jsdom": "^27.0.6",
198-
"jest-fetch-mock": "^3.0.3",
199198
"jest-mock": "^27.5.1",
200199
"jest-raw-loader": "^1.0.1",
201200
"jest-sonar-reporter": "^2.0.0",
202-
"matrix-mock-request": "^2.0.0",
201+
"matrix-mock-request": "^2.5.0",
203202
"matrix-react-test-utils": "^0.2.3",
204203
"matrix-web-i18n": "^1.3.0",
205204
"postcss-scss": "^4.0.4",

src/AddThreepid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class AddThreepid {
8585
const identityAccessToken = await authClient.getAccessToken();
8686
return MatrixClientPeg.get().requestEmailToken(
8787
emailAddress, this.clientSecret, 1,
88-
undefined, undefined, identityAccessToken,
88+
undefined, identityAccessToken,
8989
).then((res) => {
9090
this.sessionId = res.sid;
9191
return res;
@@ -142,7 +142,7 @@ export default class AddThreepid {
142142
const identityAccessToken = await authClient.getAccessToken();
143143
return MatrixClientPeg.get().requestMsisdnToken(
144144
phoneCountry, phoneNumber, this.clientSecret, 1,
145-
undefined, undefined, identityAccessToken,
145+
undefined, identityAccessToken,
146146
).then((res) => {
147147
this.sessionId = res.sid;
148148
return res;

0 commit comments

Comments
 (0)