You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-28 15:22:05 +03:00
Migrate remaining crypto tests from Cypress to Playwright (#12021)
* Fix bot MatrixClient being set up multiple times Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Migrate verification.spec.ts from Cypress to Playwright Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Migrate crypto.spec.ts from Cypress to Playwright Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add screenshot Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Record trace on-first-retry Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Don't start client when not needed Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add bot log prefixing Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Turns out we need these Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix crypto tests in rust crypto 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
0f42418b5c
commit
5104d53ddf
@ -18,8 +18,10 @@ import { JSHandle, Page } from "@playwright/test";
|
||||
import { uniqueId } from "lodash";
|
||||
|
||||
import type { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
import type { Logger } from "matrix-js-sdk/src/logger";
|
||||
import type { AddSecretStorageKeyOpts } from "matrix-js-sdk/src/secret-storage";
|
||||
import type { Credentials, HomeserverInstance } from "../plugins/homeserver";
|
||||
import type { GeneratedSecretStorageKey } from "matrix-js-sdk/src/crypto-api";
|
||||
import { Client } from "./client";
|
||||
|
||||
export interface CreateBotOpts {
|
||||
@ -60,14 +62,27 @@ const defaultCreateBotOptions = {
|
||||
bootstrapCrossSigning: true,
|
||||
} satisfies CreateBotOpts;
|
||||
|
||||
type ExtendedMatrixClient = MatrixClient & { __playwright_recovery_key: GeneratedSecretStorageKey };
|
||||
|
||||
export class Bot extends Client {
|
||||
public credentials?: Credentials;
|
||||
private handlePromise: Promise<JSHandle<ExtendedMatrixClient>>;
|
||||
|
||||
constructor(page: Page, private homeserver: HomeserverInstance, private readonly opts: CreateBotOpts) {
|
||||
super(page);
|
||||
this.opts = Object.assign({}, defaultCreateBotOptions, opts);
|
||||
}
|
||||
|
||||
public setCredentials(credentials: Credentials): void {
|
||||
if (this.credentials) throw new Error("Bot has already started");
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
public async getRecoveryKey(): Promise<GeneratedSecretStorageKey> {
|
||||
const client = await this.getClientHandle();
|
||||
return client.evaluate((cli) => cli.__playwright_recovery_key);
|
||||
}
|
||||
|
||||
private async getCredentials(): Promise<Credentials> {
|
||||
if (this.credentials) return this.credentials;
|
||||
// We want to pad the uniqueId but not the prefix
|
||||
@ -82,9 +97,36 @@ export class Bot extends Client {
|
||||
return this.credentials;
|
||||
}
|
||||
|
||||
protected async getClientHandle(): Promise<JSHandle<MatrixClient>> {
|
||||
return this.page.evaluateHandle(
|
||||
protected async getClientHandle(): Promise<JSHandle<ExtendedMatrixClient>> {
|
||||
if (this.handlePromise) return this.handlePromise;
|
||||
|
||||
this.handlePromise = this.page.evaluateHandle(
|
||||
async ({ homeserver, credentials, opts }) => {
|
||||
function getLogger(loggerName: string): Logger {
|
||||
const logger = {
|
||||
getChild: (namespace: string) => getLogger(`${loggerName}:${namespace}`),
|
||||
trace(...msg: any[]): void {
|
||||
console.trace(loggerName, ...msg);
|
||||
},
|
||||
debug(...msg: any[]): void {
|
||||
console.debug(loggerName, ...msg);
|
||||
},
|
||||
info(...msg: any[]): void {
|
||||
console.info(loggerName, ...msg);
|
||||
},
|
||||
warn(...msg: any[]): void {
|
||||
console.warn(loggerName, ...msg);
|
||||
},
|
||||
error(...msg: any[]): void {
|
||||
console.error(loggerName, ...msg);
|
||||
},
|
||||
} satisfies Logger;
|
||||
|
||||
return logger as unknown as Logger;
|
||||
}
|
||||
|
||||
const logger = getLogger(`cypress bot ${credentials.userId}`);
|
||||
|
||||
const keys = {};
|
||||
|
||||
const getCrossSigningKey = (type: string) => {
|
||||
@ -123,7 +165,8 @@ export class Bot extends Client {
|
||||
scheduler: new window.matrixcs.MatrixScheduler(),
|
||||
cryptoStore: new window.matrixcs.MemoryCryptoStore(),
|
||||
cryptoCallbacks,
|
||||
});
|
||||
logger,
|
||||
}) as ExtendedMatrixClient;
|
||||
|
||||
if (opts.autoAcceptInvites) {
|
||||
cli.on(window.matrixcs.RoomMemberEvent.Membership, (event, member) => {
|
||||
@ -180,5 +223,6 @@ export class Bot extends Client {
|
||||
opts: this.opts,
|
||||
},
|
||||
);
|
||||
return this.handlePromise;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user