Optimise Jest run in CI (#9542)
This commit is contained in:
parent
28ecdc0cb4
commit
04bc8fb71c
55 changed files with 1388 additions and 1305 deletions
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
*/
|
||||
|
||||
import EventEmitter from "events";
|
||||
import { MethodKeysOf, mocked, MockedObject, PropertyKeysOf } from "jest-mock";
|
||||
import { MethodLikeKeys, mocked, MockedObject, PropertyLikeKeys } from "jest-mock";
|
||||
import { Feature, ServerSupport } from "matrix-js-sdk/src/feature";
|
||||
import { MatrixClient, User } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
|
@ -32,7 +32,7 @@ export class MockEventEmitter<T> extends EventEmitter {
|
|||
* @param mockProperties An object with the mock property or function implementations. 'getters'
|
||||
* are correctly cloned to this event emitter.
|
||||
*/
|
||||
constructor(mockProperties: Partial<Record<MethodKeysOf<T>|PropertyKeysOf<T>, unknown>> = {}) {
|
||||
constructor(mockProperties: Partial<Record<MethodLikeKeys<T>|PropertyLikeKeys<T>, unknown>> = {}) {
|
||||
super();
|
||||
// We must use defineProperties and not assign as the former clones getters correctly,
|
||||
// whereas the latter invokes the getter and sets the return value permanently on the
|
||||
|
@ -47,7 +47,7 @@ export class MockEventEmitter<T> extends EventEmitter {
|
|||
* to MatrixClient events
|
||||
*/
|
||||
export class MockClientWithEventEmitter extends EventEmitter {
|
||||
constructor(mockProperties: Partial<Record<MethodKeysOf<MatrixClient>, unknown>> = {}) {
|
||||
constructor(mockProperties: Partial<Record<MethodLikeKeys<MatrixClient>, unknown>> = {}) {
|
||||
super();
|
||||
|
||||
Object.assign(this, mockProperties);
|
||||
|
@ -66,12 +66,13 @@ export class MockClientWithEventEmitter extends EventEmitter {
|
|||
* ```
|
||||
*/
|
||||
export const getMockClientWithEventEmitter = (
|
||||
mockProperties: Partial<Record<MethodKeysOf<MatrixClient>, unknown>>,
|
||||
mockProperties: Partial<Record<MethodLikeKeys<MatrixClient>, unknown>>,
|
||||
): MockedObject<MatrixClient> => {
|
||||
const mock = mocked(new MockClientWithEventEmitter(mockProperties) as unknown as MatrixClient);
|
||||
|
||||
jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(mock);
|
||||
|
||||
// @ts-ignore simplified test stub
|
||||
mock.canSupport = new Map();
|
||||
Object.keys(Feature).forEach(feature => {
|
||||
mock.canSupport.set(feature as Feature, ServerSupport.Stable);
|
||||
|
@ -117,7 +118,7 @@ export const mockClientMethodsEvents = () => ({
|
|||
/**
|
||||
* Returns basic mocked client methods related to server support
|
||||
*/
|
||||
export const mockClientMethodsServer = (): Partial<Record<MethodKeysOf<MatrixClient>, unknown>> => ({
|
||||
export const mockClientMethodsServer = (): Partial<Record<MethodLikeKeys<MatrixClient>, unknown>> => ({
|
||||
doesServerSupportSeparateAddAndBind: jest.fn(),
|
||||
getIdentityServerUrl: jest.fn(),
|
||||
getHomeserverUrl: jest.fn(),
|
||||
|
@ -130,14 +131,14 @@ export const mockClientMethodsServer = (): Partial<Record<MethodKeysOf<MatrixCli
|
|||
|
||||
export const mockClientMethodsDevice = (
|
||||
deviceId = 'test-device-id',
|
||||
): Partial<Record<MethodKeysOf<MatrixClient>, unknown>> => ({
|
||||
): Partial<Record<MethodLikeKeys<MatrixClient>, unknown>> => ({
|
||||
getDeviceId: jest.fn().mockReturnValue(deviceId),
|
||||
getDeviceEd25519Key: jest.fn(),
|
||||
getDevices: jest.fn().mockResolvedValue({ devices: [] }),
|
||||
});
|
||||
|
||||
export const mockClientMethodsCrypto = (): Partial<Record<
|
||||
MethodKeysOf<MatrixClient> & PropertyKeysOf<MatrixClient>, unknown>
|
||||
MethodLikeKeys<MatrixClient> & PropertyLikeKeys<MatrixClient>, unknown>
|
||||
> => ({
|
||||
isCryptoEnabled: jest.fn(),
|
||||
isSecretStorageReady: jest.fn(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue