Simplify registration with email validation (#11398)

This commit is contained in:
Michael Telatynski
2023-08-15 16:14:53 +01:00
committed by GitHub
parent beafe686a9
commit 0842559fb2
17 changed files with 437 additions and 55 deletions
+2
View File
@@ -40,6 +40,8 @@ import "./network";
import "./composer";
import "./proxy";
import "./axe";
import "./mailhog";
import "./promise";
installLogsCollector({
// specify the types of logs to collect (and report to the node console at the end of the test)
+3
View File
@@ -28,6 +28,9 @@ export interface StartHomeserverOpts {
/** Port of an OAuth server to configure the homeserver to use */
oAuthServerPort?: number;
/** Additional variables to inject into the configuration template **/
variables?: Record<string, string | number>;
}
declare global {
+54
View File
@@ -0,0 +1,54 @@
/*
Copyright 2023 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.
*/
/// <reference types="cypress" />
import mailhog from "mailhog";
import Chainable = Cypress.Chainable;
import { Instance } from "../plugins/mailhog";
export interface Mailhog {
api: mailhog.API;
instance: Instance;
}
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
startMailhog(): Chainable<Mailhog>;
stopMailhog(instance: Mailhog): Chainable<void>;
}
}
}
Cypress.Commands.add("startMailhog", (): Chainable<Mailhog> => {
return cy.task<Instance>("mailhogStart", { log: false }).then((x) => {
Cypress.log({ name: "startHomeserver", message: `Started mailhog instance ${x.containerId}` });
return {
api: mailhog({
host: "localhost",
port: x.httpPort,
}),
instance: x,
};
});
});
Cypress.Commands.add("stopMailhog", (mailhog: Mailhog): Chainable<void> => {
return cy.task("mailhogStop", mailhog.instance.containerId);
});
+58
View File
@@ -0,0 +1,58 @@
/*
Copyright 2023 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.
*/
/// <reference types="cypress" />
import Chainable = Cypress.Chainable;
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
/**
* Utility wrapper around promises to help control flow in tests
* Calls `fn` function `tries` times, with a sleep of `interval` between calls.
* Ensure you do not rely on any effects of calling any `cy.*` functions within the body of `fn`
* as the calls will not happen until after waitForPromise returns.
* @param fn the function to retry
* @param tries the number of tries to call it
* @param interval the time interval between tries
*/
waitForPromise(fn: () => Promise<unknown>, tries?: number, interval?: number): Chainable<unknown>;
}
}
}
function waitForPromise(fn: () => Promise<unknown>, tries = 10, interval = 1000): Chainable<unknown> {
return cy.then(
() =>
new Cypress.Promise(async (resolve, reject) => {
for (let i = 0; i < tries; i++) {
try {
const v = await fn();
resolve(v);
} catch {
await new Cypress.Promise((resolve) => setTimeout(resolve, interval));
}
}
reject();
}),
);
}
Cypress.Commands.add("waitForPromise", waitForPromise);
export {};