Cypress: add a way to specify the prefix for userIDs (#9787)

This helps a lot with debugging tests where there are multiple users.
This commit is contained in:
Richard van der Hoff 2022-12-19 13:12:01 +00:00 committed by GitHub
parent 3ec75fdd3c
commit ddfa627ce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View file

@ -158,8 +158,8 @@ describe("Cryptography", function () {
cy.startSynapse("default")
.as("synapse")
.then((synapse: SynapseInstance) => {
cy.initTestUser(synapse, "Alice");
cy.getBot(synapse, { displayName: "Bob", autoAcceptInvites: false }).as("bob");
cy.initTestUser(synapse, "Alice", undefined, "alice_");
cy.getBot(synapse, { displayName: "Bob", autoAcceptInvites: false, userIdPrefix: "bob_" }).as("bob");
});
});

View file

@ -22,6 +22,10 @@ import { Credentials } from "./synapse";
import Chainable = Cypress.Chainable;
interface CreateBotOpts {
/**
* A prefix to use for the userid. If unspecified, "bot_" will be used.
*/
userIdPrefix?: string;
/**
* Whether the bot should automatically accept all invites.
*/
@ -41,6 +45,7 @@ interface CreateBotOpts {
}
const defaultCreateBotOptions = {
userIdPrefix: "bot_",
autoAcceptInvites: true,
startClient: true,
bootstrapCrossSigning: true,
@ -153,7 +158,7 @@ function setupBotClient(
Cypress.Commands.add("getBot", (synapse: SynapseInstance, opts: CreateBotOpts): Chainable<MatrixClient> => {
opts = Object.assign({}, defaultCreateBotOptions, opts);
const username = Cypress._.uniqueId("userId_");
const username = Cypress._.uniqueId(opts.userIdPrefix);
const password = Cypress._.uniqueId("password_");
return cy.registerUser(synapse, username, password, opts.displayName).then((credentials) => {
cy.log(`Registered bot user ${username} with displayname ${opts.displayName}`);

View file

@ -37,11 +37,14 @@ declare global {
* @param synapse the synapse returned by startSynapse
* @param displayName the displayName to give the test user
* @param prelaunchFn optional function to run before the app is visited
* @param userIdPrefix optional prefix to use for the generated user id. If unspecified, `user_` will be
* useed.
*/
initTestUser(
synapse: SynapseInstance,
displayName: string,
prelaunchFn?: () => void,
userIdPrefix?: string,
): Chainable<UserCredentials>;
/**
* Logs into synapse with the given username/password
@ -91,7 +94,12 @@ Cypress.Commands.add(
// eslint-disable-next-line max-len
Cypress.Commands.add(
"initTestUser",
(synapse: SynapseInstance, displayName: string, prelaunchFn?: () => void): Chainable<UserCredentials> => {
(
synapse: SynapseInstance,
displayName: string,
prelaunchFn?: () => void,
userIdPrefix = "user_",
): Chainable<UserCredentials> => {
// XXX: work around Cypress not clearing IDB between tests
cy.window({ log: false }).then((win) => {
win.indexedDB.databases()?.then((databases) => {
@ -101,7 +109,7 @@ Cypress.Commands.add(
});
});
const username = Cypress._.uniqueId("userId_");
const username = Cypress._.uniqueId(userIdPrefix);
const password = Cypress._.uniqueId("password_");
return cy
.registerUser(synapse, username, password, displayName)