Skip to content

Update jest to v30 (major) #4875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@
"@stylistic/eslint-plugin": "^4.0.0",
"@types/content-type": "^1.1.5",
"@types/debug": "^4.1.7",
"@types/jest": "^29.0.0",
"@types/node": "18",
"@types/sdp-transform": "^2.4.5",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"babel-jest": "^29.0.0",
"babel-jest": "^30.0.0",
"babel-plugin-search-and-replace": "^1.1.1",
"debug": "^4.3.4",
"eslint": "8.57.1",
Expand All @@ -108,10 +107,10 @@
"fetch-mock": "11.1.5",
"fetch-mock-jest": "^1.5.1",
"husky": "^9.0.0",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0",
"jest": "^30.0.0",
"jest-environment-jsdom": "^30.0.0",
"jest-localstorage-mock": "^2.4.6",
"jest-mock": "^29.0.0",
"jest-mock": "^30.0.0",
"knip": "^5.0.0",
"lint-staged": "^16.0.0",
"matrix-mock-request": "^2.5.0",
Expand Down
1 change: 1 addition & 0 deletions spec/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ limitations under the License.
// load olm before the sdk if possible
import "./olm-loader";

import { expect } from "@jest/globals";
import MockHttpBackend from "matrix-mock-request";

import type { IDeviceKeys, IOneTimeKey } from "../src/@types/crypto";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/cross-signing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import fetchMock from "fetch-mock-jest";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
Expand Down Expand Up @@ -256,7 +257,7 @@
// a second call should do nothing except GET requests
fetchMock.mockClear();
await bootstrapCrossSigning(authDict);
const calls = fetchMock.calls((url, opts) => opts.method != "GET");

Check failure on line 260 in spec/integ/crypto/cross-signing.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'opts' implicitly has an 'any' type.

Check failure on line 260 in spec/integ/crypto/cross-signing.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'url' implicitly has an 'any' type.
expect(calls.length).toEqual(0);
});

Expand Down Expand Up @@ -421,7 +422,7 @@
url: new RegExp("/_matrix/client/v3/keys/device_signing/upload"),
name: "upload-keys",
},
(url, options) => {

Check failure on line 425 in spec/integ/crypto/cross-signing.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'options' implicitly has an 'any' type.

Check failure on line 425 in spec/integ/crypto/cross-signing.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'url' implicitly has an 'any' type.
const content = JSON.parse(options.body as string);
resolve(content);
return {};
Expand Down
7 changes: 4 additions & 3 deletions spec/integ/crypto/crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import anotherjson from "another-json";
import fetchMock from "fetch-mock-jest";
import "fake-indexeddb/auto";
Expand Down Expand Up @@ -171,7 +172,7 @@
return new Promise<IContent>((resolve) => {
fetchMock.putOnce(
new RegExp("/send/m.room.encrypted/"),
(url, request) => {

Check failure on line 175 in spec/integ/crypto/crypto.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'request' implicitly has an 'any' type.

Check failure on line 175 in spec/integ/crypto/crypto.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'url' implicitly has an 'any' type.
const content = JSON.parse(request.body as string);
resolve(content);
return { event_id: "$event_id" };
Expand Down Expand Up @@ -2068,7 +2069,7 @@
const awaitKeyUploaded = new Promise<KeyBackup>((resolve) => {
fetchMock.put(
"path:/_matrix/client/v3/room_keys/keys",
(url, request) => {

Check failure on line 2072 in spec/integ/crypto/crypto.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'request' implicitly has an 'any' type.

Check failure on line 2072 in spec/integ/crypto/crypto.spec.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'url' implicitly has an 'any' type.
const uploadPayload: KeyBackup = JSON.parse((request.body as string) ?? "{}");
resolve(uploadPayload);
return {
Expand Down Expand Up @@ -2300,7 +2301,7 @@
client2?.stopClient();
});

test("Sending a message in a room where the server is hiding the state event does not send a plaintext event", async () => {
it("Sending a message in a room where the server is hiding the state event does not send a plaintext event", async () => {
// Alice is in an encrypted room
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2" });
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
Expand All @@ -2319,7 +2320,7 @@
await expectSendMessageToFail(client2);
});

test("Changes to the rotation period should be ignored", async () => {
it("Changes to the rotation period should be ignored", async () => {
// Alice is in an encrypted room, where the rotation period is set to 2 messages
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2", rotation_period_msgs: 2 });
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
Expand Down Expand Up @@ -2357,7 +2358,7 @@
expect(msg3Content.session_id).not.toEqual(msg1Content.session_id);
});

test("Changes to the rotation period should be ignored after a client restart", async () => {
it("Changes to the rotation period should be ignored after a client restart", async () => {
// Alice is in an encrypted room, where the rotation period is set to 2 messages
const encryptionState = mkEncryptionEvent({ algorithm: "m.megolm.v1.aes-sha2", rotation_period_msgs: 2 });
syncResponder.sendOrQueueSyncResponse(getSyncResponseWithState([encryptionState]));
Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/device-dehydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { describe, expect, it, jest } from "@jest/globals";
import "fake-indexeddb/auto";
import fetchMock from "fetch-mock-jest";

Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/megolm-backup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import fetchMock from "fetch-mock-jest";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/olm-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { expect } from "@jest/globals";
import Olm from "@matrix-org/olm";
import anotherjson from "another-json";

Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
import fetchMock from "fetch-mock-jest";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/to-device-messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";
import fetchMock from "fetch-mock-jest";
import "fake-indexeddb/auto";
import { IDBFactory } from "fake-indexeddb";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import "fake-indexeddb/auto";

import { afterEach, beforeEach, beforeAll, describe, expect, it, jest } from "@jest/globals";
import anotherjson from "another-json";
import fetchMock from "fetch-mock-jest";
import { IDBFactory } from "fake-indexeddb";
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-event-emitter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";

import type HttpBackend from "matrix-mock-request";
import {
ClientEvent,
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-event-timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";

import * as utils from "../test-utils/test-utils";
import {
ClientEvent,
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";

import type HttpBackend from "matrix-mock-request";
import * as utils from "../test-utils/test-utils";
import { type IStoredClientOpts, MatrixClient } from "../../src/client";
Expand Down
17 changes: 17 additions & 0 deletions spec/integ/matrix-client-opts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
Copyright 2025 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";
import HttpBackend from "matrix-mock-request";

import * as utils from "../test-utils/test-utils";
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-relations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";

import type HttpBackend from "matrix-mock-request";
import { Direction, type MatrixClient, MatrixScheduler } from "../../src/matrix";
import { TestClient } from "../TestClient";
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-retrying.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";

import type HttpBackend from "matrix-mock-request";
import { EventStatus, type MatrixClient, MatrixScheduler, MsgType, RoomEvent } from "../../src/matrix";
import { Room } from "../../src/models/room";
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-room-timeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from "@jest/globals";

import type HttpBackend from "matrix-mock-request";
import * as utils from "../test-utils/test-utils";
import { EventStatus } from "../../src/models/event";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/matrix-client-syncing-errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import "fake-indexeddb/auto";
import fetchMock from "fetch-mock-jest";

Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-syncing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";

import "fake-indexeddb/auto";

import type HttpBackend from "matrix-mock-request";
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/matrix-client-unread-notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";

import "fake-indexeddb/auto";

import type HttpBackend from "matrix-mock-request";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/rendezvous/MSC4108SignInWithQR.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it, jest } from "@jest/globals";
import { QrCodeData, QrCodeMode } from "@matrix-org/matrix-sdk-crypto-wasm";
import { mocked } from "jest-mock";
import fetchMock from "fetch-mock-jest";
Expand Down
1 change: 1 addition & 0 deletions spec/integ/sliding-sync-sdk.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

// eslint-disable-next-line no-restricted-imports
import { fail } from "assert";
import { afterEach, afterAll, beforeAll, describe, expect, it, jest } from "@jest/globals";

import type MockHttpBackend from "matrix-mock-request";
import {
Expand Down
2 changes: 2 additions & 0 deletions spec/integ/sliding-sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterAll, beforeAll, describe, expect, it } from "@jest/globals";

// eslint-disable-next-line no-restricted-imports
import type EventEmitter from "events";
import type MockHttpBackend from "matrix-mock-request";
Expand Down
6 changes: 4 additions & 2 deletions spec/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { jest } from "@jest/globals";

jest.mock("../src/http-api/utils", () => ({
...jest.requireActual("../src/http-api/utils"),
...jest.requireActual<object>("../src/http-api/utils"),
// We mock timeoutSignal otherwise it causes tests to leave timers running
timeoutSignal: () => new AbortController().signal,
}));

// Dont make test fail too soon due to timeouts while debugging.
// Don't make test fail too soon due to timeouts while debugging.
if (process.env.VSCODE_INSPECTOR_OPTIONS) {
jest.setTimeout(60 * 1000 * 5); // 5 minutes
}
2 changes: 2 additions & 0 deletions spec/slowReporter.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { afterEach, beforeEach, afterAll, beforeAll, describe, expect, it, jest } from "@jest/globals";

/* eslint-disable no-console */

class JestSlowTestReporter {
Expand Down
1 change: 1 addition & 0 deletions spec/test-utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { jest } from "@jest/globals";
import { type MethodLikeKeys, mocked, type MockedObject } from "jest-mock";

import { type ClientEventHandlerMap, type EmittedEvents, type MatrixClient } from "../../src/client";
Expand Down
4 changes: 3 additions & 1 deletion spec/test-utils/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { type jest } from "@jest/globals";

/**
* Filter emitter.emit mock calls to find relevant events
* eg:
Expand All @@ -24,5 +26,5 @@ limitations under the License.
* expect(beaconLivenessEmits.length).toBe(1);
* ```
*/
export const filterEmitCallsByEventType = (eventType: string, spy: jest.SpyInstance<any, any[]>) =>
export const filterEmitCallsByEventType = (eventType: string, spy: jest.Spied<(...args: any[]) => any>) =>
spy.mock.calls.filter((args) => args[0] === eventType);
1 change: 1 addition & 0 deletions spec/test-utils/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import "../olm-loader";

// eslint-disable-next-line no-restricted-imports
import type EventEmitter from "events";

Check failure on line 5 in spec/test-utils/test-utils.ts

View workflow job for this annotation

GitHub Actions / ESLint

There should be at least one empty line between import groups
import { jest } from "@jest/globals";

Check failure on line 6 in spec/test-utils/test-utils.ts

View workflow job for this annotation

GitHub Actions / ESLint

`@jest/globals` import should occur before type import of `events`

Check failure on line 6 in spec/test-utils/test-utils.ts

View workflow job for this annotation

GitHub Actions / ESLint

There should be at least one empty line between import groups
import { logger } from "../../src/logger";
import {
type IContent,
Expand Down
2 changes: 2 additions & 0 deletions spec/test-utils/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { expect } from "@jest/globals";

import { RelationType } from "../../src/@types/event";
import { type MatrixClient } from "../../src/client";
import { type MatrixEvent, MatrixEventEvent } from "../../src/models/event";
Expand Down
Loading
Loading