You've already forked element-web
mirror of
https://github.com/element-hq/element-web.git
synced 2025-08-08 03:42:14 +03:00
Simplify playwright (#28988)
* Simplify types Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix typos 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
381b2ea343
commit
e2bd040c88
@@ -13,7 +13,7 @@ Please see LICENSE files in the repository root for full details.
|
|||||||
import { expect, test } from "../../element-web-test";
|
import { expect, test } from "../../element-web-test";
|
||||||
|
|
||||||
test.use({
|
test.use({
|
||||||
synapseConfigOptions: {
|
synapseConfig: {
|
||||||
allow_guest_access: true,
|
allow_guest_access: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@@ -13,7 +13,7 @@ import { TestClientServerAPI } from "../csAPI";
|
|||||||
import { masHomeserver } from "../../plugins/homeserver/synapse/masHomeserver.ts";
|
import { masHomeserver } from "../../plugins/homeserver/synapse/masHomeserver.ts";
|
||||||
|
|
||||||
// These tests register an account with MAS because then we go through the "normal" registration flow
|
// These tests register an account with MAS because then we go through the "normal" registration flow
|
||||||
// and crypto gets set up. Using the 'user' fixture create a a user an synthesizes an existing login,
|
// and crypto gets set up. Using the 'user' fixture create a user and synthesizes an existing login,
|
||||||
// which is faster but leaves us without crypto set up.
|
// which is faster but leaves us without crypto set up.
|
||||||
test.use(masHomeserver);
|
test.use(masHomeserver);
|
||||||
test.describe("Encryption state after registration", () => {
|
test.describe("Encryption state after registration", () => {
|
||||||
|
@@ -21,7 +21,7 @@ function getMemberTileByName(page: Page, name: string): Locator {
|
|||||||
|
|
||||||
test.use({
|
test.use({
|
||||||
displayName: NAME,
|
displayName: NAME,
|
||||||
synapseConfigOptions: {
|
synapseConfig: {
|
||||||
experimental_features: {
|
experimental_features: {
|
||||||
msc2697_enabled: false,
|
msc2697_enabled: false,
|
||||||
msc3814_enabled: true,
|
msc3814_enabled: true,
|
||||||
|
@@ -12,7 +12,7 @@ const ROOM_NAME = "Test room";
|
|||||||
const NAME = "Alice";
|
const NAME = "Alice";
|
||||||
|
|
||||||
test.use({
|
test.use({
|
||||||
synapseConfigOptions: {
|
synapseConfig: {
|
||||||
presence: {
|
presence: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
include_offline_users_on_sync: false,
|
include_offline_users_on_sync: false,
|
||||||
|
@@ -6,7 +6,15 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect as baseExpect, Locator, Page, ExpectMatcherState, ElementHandle } from "@playwright/test";
|
import {
|
||||||
|
expect as baseExpect,
|
||||||
|
Locator,
|
||||||
|
Page,
|
||||||
|
ExpectMatcherState,
|
||||||
|
ElementHandle,
|
||||||
|
PlaywrightTestArgs,
|
||||||
|
Fixtures as _Fixtures,
|
||||||
|
} from "@playwright/test";
|
||||||
import { sanitizeForFilePath } from "playwright-core/lib/utils";
|
import { sanitizeForFilePath } from "playwright-core/lib/utils";
|
||||||
import AxeBuilder from "@axe-core/playwright";
|
import AxeBuilder from "@axe-core/playwright";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
@@ -19,7 +27,7 @@ import { Crypto } from "./pages/crypto";
|
|||||||
import { Toasts } from "./pages/toasts";
|
import { Toasts } from "./pages/toasts";
|
||||||
import { Bot, CreateBotOpts } from "./pages/bot";
|
import { Bot, CreateBotOpts } from "./pages/bot";
|
||||||
import { Webserver } from "./plugins/webserver";
|
import { Webserver } from "./plugins/webserver";
|
||||||
import { test as base } from "./services.ts";
|
import { Options, Services, test as base } from "./services.ts";
|
||||||
|
|
||||||
// Enable experimental service worker support
|
// Enable experimental service worker support
|
||||||
// See https://playwright.dev/docs/service-workers-experimental#how-to-enable
|
// See https://playwright.dev/docs/service-workers-experimental#how-to-enable
|
||||||
@@ -45,7 +53,7 @@ interface CredentialsWithDisplayName extends Credentials {
|
|||||||
displayName: string;
|
displayName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Fixtures {
|
export interface TestFixtures {
|
||||||
axe: AxeBuilder;
|
axe: AxeBuilder;
|
||||||
checkA11y: () => Promise<void>;
|
checkA11y: () => Promise<void>;
|
||||||
|
|
||||||
@@ -102,7 +110,9 @@ export interface Fixtures {
|
|||||||
disablePresence: boolean;
|
disablePresence: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test = base.extend<Fixtures>({
|
type CombinedTestFixtures = PlaywrightTestArgs & TestFixtures;
|
||||||
|
export type Fixtures = _Fixtures<CombinedTestFixtures, Services & Options, CombinedTestFixtures>;
|
||||||
|
export const test = base.extend<TestFixtures>({
|
||||||
context: async ({ context }, use, testInfo) => {
|
context: async ({ context }, use, testInfo) => {
|
||||||
// We skip tests instead of using grep-invert to still surface the counts in the html report
|
// We skip tests instead of using grep-invert to still surface the counts in the html report
|
||||||
test.skip(
|
test.skip(
|
||||||
@@ -150,7 +160,7 @@ export const test = base.extend<Fixtures>({
|
|||||||
const displayName = testDisplayName ?? _.sample(names)!;
|
const displayName = testDisplayName ?? _.sample(names)!;
|
||||||
|
|
||||||
const credentials = await homeserver.registerUser(`user_${testInfo.testId}`, password, displayName);
|
const credentials = await homeserver.registerUser(`user_${testInfo.testId}`, password, displayName);
|
||||||
console.log(`Registered test user @user:localhost with displayname ${displayName}`);
|
console.log(`Registered test user ${credentials.userId} with displayname ${displayName}`);
|
||||||
|
|
||||||
await use({
|
await use({
|
||||||
...credentials,
|
...credentials,
|
||||||
|
@@ -121,7 +121,7 @@ export class Bot extends Client {
|
|||||||
return logger as unknown as Logger;
|
return logger as unknown as Logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
const logger = getLogger(`cypress bot ${credentials.userId}`);
|
const logger = getLogger(`bot ${credentials.userId}`);
|
||||||
|
|
||||||
const keys = {};
|
const keys = {};
|
||||||
|
|
||||||
|
@@ -6,12 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures } from "@playwright/test";
|
|
||||||
|
|
||||||
import { DendriteContainer, PineconeContainer } from "../../../testcontainers/dendrite.ts";
|
import { DendriteContainer, PineconeContainer } from "../../../testcontainers/dendrite.ts";
|
||||||
import { Services } from "../../../services.ts";
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
export const dendriteHomeserver: Fixtures<{}, Services> = {
|
export const dendriteHomeserver: Fixtures = {
|
||||||
_homeserver: [
|
_homeserver: [
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
async ({}, use) => {
|
async ({}, use) => {
|
||||||
|
@@ -6,11 +6,9 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures } from "@playwright/test";
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
export const consentHomeserver: Fixtures = {
|
||||||
|
|
||||||
export const consentHomeserver: Fixtures<{}, Services> = {
|
|
||||||
_homeserver: [
|
_homeserver: [
|
||||||
async ({ _homeserver: container, mailhog }, use) => {
|
async ({ _homeserver: container, mailhog }, use) => {
|
||||||
container
|
container
|
||||||
|
@@ -6,11 +6,9 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures } from "@playwright/test";
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
export const emailHomeserver: Fixtures = {
|
||||||
|
|
||||||
export const emailHomeserver: Fixtures<{}, Services> = {
|
|
||||||
_homeserver: [
|
_homeserver: [
|
||||||
async ({ _homeserver: container, mailhog }, use) => {
|
async ({ _homeserver: container, mailhog }, use) => {
|
||||||
container.withConfig({
|
container.withConfig({
|
||||||
|
@@ -6,13 +6,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures, PlaywrightTestArgs } from "@playwright/test";
|
|
||||||
import { TestContainers } from "testcontainers";
|
import { TestContainers } from "testcontainers";
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
|
||||||
import { OAuthServer } from "../../oauth_server";
|
import { OAuthServer } from "../../oauth_server";
|
||||||
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
export const legacyOAuthHomeserver: Fixtures<PlaywrightTestArgs, Services, PlaywrightTestArgs> = {
|
export const legacyOAuthHomeserver: Fixtures = {
|
||||||
oAuthServer: [
|
oAuthServer: [
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
async ({}, use) => {
|
async ({}, use) => {
|
||||||
|
@@ -6,14 +6,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures, PlaywrightTestArgs } from "@playwright/test";
|
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
|
||||||
import { Fixtures as BaseFixtures } from "../../../element-web-test.ts";
|
|
||||||
import { MatrixAuthenticationServiceContainer } from "../../../testcontainers/mas.ts";
|
import { MatrixAuthenticationServiceContainer } from "../../../testcontainers/mas.ts";
|
||||||
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
type Fixture = PlaywrightTestArgs & BaseFixtures;
|
export const masHomeserver: Fixtures = {
|
||||||
export const masHomeserver: Fixtures<Fixture, Services, Fixture> = {
|
|
||||||
mas: [
|
mas: [
|
||||||
async ({ _homeserver: homeserver, logger, network, postgres, mailhog }, use) => {
|
async ({ _homeserver: homeserver, logger, network, postgres, mailhog }, use) => {
|
||||||
const config = {
|
const config = {
|
||||||
|
@@ -5,15 +5,13 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Fixtures } from "@playwright/test";
|
import { Fixtures } from "../../../element-web-test.ts";
|
||||||
|
|
||||||
import { Services } from "../../../services.ts";
|
export const uiaLongSessionTimeoutHomeserver: Fixtures = {
|
||||||
|
synapseConfig: [
|
||||||
export const uiaLongSessionTimeoutHomeserver: Fixtures<{}, Services> = {
|
async ({ synapseConfig }, use) => {
|
||||||
synapseConfigOptions: [
|
|
||||||
async ({ synapseConfigOptions }, use) => {
|
|
||||||
await use({
|
await use({
|
||||||
...synapseConfigOptions,
|
...synapseConfig,
|
||||||
ui_auth: {
|
ui_auth: {
|
||||||
session_timeout: "300s",
|
session_timeout: "300s",
|
||||||
},
|
},
|
||||||
|
@@ -10,14 +10,14 @@ import mailhog from "mailhog";
|
|||||||
import { Network, StartedNetwork } from "testcontainers";
|
import { Network, StartedNetwork } from "testcontainers";
|
||||||
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";
|
||||||
|
|
||||||
import { SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts";
|
import { SynapseConfig, SynapseContainer } from "./testcontainers/synapse.ts";
|
||||||
import { Logger } from "./logger.ts";
|
import { Logger } from "./logger.ts";
|
||||||
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
|
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
|
||||||
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
|
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
|
||||||
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";
|
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";
|
||||||
import { OAuthServer } from "./plugins/oauth_server";
|
import { OAuthServer } from "./plugins/oauth_server";
|
||||||
|
|
||||||
interface TestFixtures {
|
export interface TestFixtures {
|
||||||
mailhogClient: mailhog.API;
|
mailhogClient: mailhog.API;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ export interface Services {
|
|||||||
postgres: StartedPostgreSqlContainer;
|
postgres: StartedPostgreSqlContainer;
|
||||||
mailhog: StartedMailhogContainer;
|
mailhog: StartedMailhogContainer;
|
||||||
|
|
||||||
synapseConfigOptions: SynapseConfigOptions;
|
synapseConfig: SynapseConfig;
|
||||||
_homeserver: HomeserverContainer<any>;
|
_homeserver: HomeserverContainer<any>;
|
||||||
homeserver: StartedHomeserverContainer;
|
homeserver: StartedHomeserverContainer;
|
||||||
// Set in masHomeserver only
|
// Set in masHomeserver only
|
||||||
@@ -37,7 +37,9 @@ export interface Services {
|
|||||||
oAuthServer?: OAuthServer;
|
oAuthServer?: OAuthServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test = base.extend<TestFixtures, Services>({
|
export interface Options {}
|
||||||
|
|
||||||
|
export const test = base.extend<TestFixtures, Services & Options>({
|
||||||
logger: [
|
logger: [
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
async ({}, use) => {
|
async ({}, use) => {
|
||||||
@@ -101,7 +103,7 @@ export const test = base.extend<TestFixtures, Services>({
|
|||||||
await container.client.deleteAll();
|
await container.client.deleteAll();
|
||||||
},
|
},
|
||||||
|
|
||||||
synapseConfigOptions: [{}, { option: true, scope: "worker" }],
|
synapseConfig: [{}, { scope: "worker" }],
|
||||||
_homeserver: [
|
_homeserver: [
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
async ({}, use) => {
|
async ({}, use) => {
|
||||||
@@ -111,12 +113,12 @@ export const test = base.extend<TestFixtures, Services>({
|
|||||||
{ scope: "worker" },
|
{ scope: "worker" },
|
||||||
],
|
],
|
||||||
homeserver: [
|
homeserver: [
|
||||||
async ({ logger, network, _homeserver: homeserver, synapseConfigOptions, mas }, use) => {
|
async ({ logger, network, _homeserver: homeserver, synapseConfig, mas }, use) => {
|
||||||
const container = await homeserver
|
const container = await homeserver
|
||||||
.withNetwork(network)
|
.withNetwork(network)
|
||||||
.withNetworkAliases("homeserver")
|
.withNetworkAliases("homeserver")
|
||||||
.withLogConsumer(logger.getConsumer("synapse"))
|
.withLogConsumer(logger.getConsumer("synapse"))
|
||||||
.withConfig(synapseConfigOptions)
|
.withConfig(synapseConfig)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
await use(container);
|
await use(container);
|
||||||
|
@@ -138,7 +138,7 @@ const DEFAULT_CONFIG = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SynapseConfigOptions = Partial<typeof DEFAULT_CONFIG>;
|
export type SynapseConfig = Partial<typeof DEFAULT_CONFIG>;
|
||||||
|
|
||||||
export class SynapseContainer extends GenericContainer implements HomeserverContainer<typeof DEFAULT_CONFIG> {
|
export class SynapseContainer extends GenericContainer implements HomeserverContainer<typeof DEFAULT_CONFIG> {
|
||||||
private config: typeof DEFAULT_CONFIG;
|
private config: typeof DEFAULT_CONFIG;
|
||||||
|
Reference in New Issue
Block a user