Move Enterprise Erin tests from Puppeteer to Cypress (#8569)

* Move Enterprise Erin tests from Puppeteer to Cypress

* delint

* types

* Fix double space

* Better handle logout in Lifecycle

* Fix test by awaiting the network request

* Improve some logout handlings

* Try try try again

* Delint

* Fix tests

* Delint
This commit is contained in:
Michael Telatynski 2022-05-26 11:12:49 +01:00 committed by GitHub
parent 7efd7b67ea
commit 655bca63e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 131 additions and 150 deletions

View file

@ -27,13 +27,12 @@ import { RestMultiSession } from "./rest/multi";
import { RestSession } from "./rest/session";
import { stickerScenarios } from './scenarios/sticker';
import { userViewScenarios } from "./scenarios/user-view";
import { ssoCustomisationScenarios } from "./scenarios/sso-customisations";
import { updateScenarios } from "./scenarios/update";
export async function scenario(createSession: (s: string) => Promise<ElementSession>,
restCreator: RestSessionCreator): Promise<void> {
let firstUser = true;
async function createUser(username) {
async function createUser(username: string) {
const session = await createSession(username);
if (firstUser) {
// only show browser version for first browser opened
@ -65,12 +64,6 @@ export async function scenario(createSession: (s: string) => Promise<ElementSess
const stickerSession = await createSession("sally");
await stickerScenarios("sally", "ilikestickers", stickerSession, restCreator);
// we spawn yet another session for SSO stuff because it involves authentication and
// logout, which can/does affect other tests dramatically. See notes above regarding
// stickers for the performance loss of doing this.
const ssoSession = await createUser("enterprise_erin");
await ssoCustomisationScenarios(ssoSession);
// Create a new window to test app auto-updating
const updateSession = await createSession("update");
await updateScenarios(updateSession);

View file

@ -1,50 +0,0 @@
/*
Copyright 2022 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 { strict as assert } from "assert";
import { ElementSession } from "../session";
import { logout } from "../usecases/logout";
import { applyConfigChange } from "../util";
export async function ssoCustomisationScenarios(session: ElementSession): Promise<void> {
console.log(" injecting logout customisations for SSO scenarios:");
await session.delay(1000); // wait for dialogs to close
await applyConfigChange(session, {
// we redirect to config.json because it's a predictable page that isn't Element
// itself. We could use example.org, matrix.org, or something else, however this
// puts dependency of external infrastructure on our tests. In the same vein, we
// don't really want to figure out how to ship a `test-landing.html` page when
// running with an uncontrolled Element (via `./run.sh --app-url http://localhost:8080`).
// Using the config.json is just as fine, and we can search for strategic names.
'logout_redirect_url': '/config.json',
});
await logoutCanCauseRedirect(session);
}
async function logoutCanCauseRedirect(session: ElementSession): Promise<void> {
await logout(session, false); // we'll check the login page ourselves, so don't assert
session.log.step("waits for redirect to config.json (as external page)");
const foundLoginUrl = await session.poll(async () => {
const url = session.page.url();
return url === session.url('/config.json');
});
assert(foundLoginUrl);
session.log.done();
}

View file

@ -1,43 +0,0 @@
/*
Copyright 2022 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 { strict as assert } from 'assert';
import { ElementSession } from "../session";
export async function logout(session: ElementSession, assertLoginPage = true): Promise<void> {
session.log.startGroup("logs out");
session.log.step("navigates to user menu");
const userButton = await session.query('.mx_UserMenu > div.mx_AccessibleButton');
await userButton.click();
session.log.done();
session.log.step("clicks the 'Sign Out' button");
const signOutButton = await session.query('.mx_UserMenu_contextMenu .mx_UserMenu_iconSignOut');
await signOutButton.click();
session.log.done();
if (assertLoginPage) {
const foundLoginUrl = await session.poll(async () => {
const url = session.page.url();
return url === session.url('/#/login');
});
assert(foundLoginUrl);
}
session.log.endGroup();
}

View file

@ -28,7 +28,7 @@ export const range = function(start: number, amount: number, step = 1): Array<nu
return r;
};
export const delay = function(ms): Promise<void> {
export const delay = function(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
};
@ -44,17 +44,6 @@ export const measureStop = function(session: ElementSession, name: string): Prom
}, name);
};
// TODO: Proper types on `config` - for some reason won't accept an import of ConfigOptions.
export async function applyConfigChange(session: ElementSession, config: any): Promise<void> {
await session.page.evaluate((_config) => {
// note: we can't *set* the object because the window version is effectively a pointer.
for (const [k, v] of Object.entries(_config)) {
// @ts-ignore - for some reason it's not picking up on global.d.ts types.
window.mxReactSdkConfig[k] = v;
}
}, config);
}
export async function serializeLog(msg: ConsoleMessage): Promise<string> {
// 9 characters padding is somewhat arbitrary ("warning".length + some)
let s = `${new Date().toISOString()} | ${ padEnd(msg.type(), 9, ' ')}| ${msg.text()} `; // trailing space is intentional