diff --git a/playwright/plugins/homeserver/dendrite/index.ts b/playwright/plugins/homeserver/dendrite/index.ts index acdb45cffff..c9cb3332eb2 100644 --- a/playwright/plugins/homeserver/dendrite/index.ts +++ b/playwright/plugins/homeserver/dendrite/index.ts @@ -6,39 +6,32 @@ 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. */ -// export const dendriteHomeserver: Fixtures & Fixtures = { -// _homeserver: async ({ request }, use) => { -// const container = new SynapseContainer(request); -// await use(container); -// -// container.withConfig({ -// oidc_providers: [ -// { -// idp_id: "test", -// idp_name: "OAuth test", -// issuer: `http://localhost:${port}/oauth`, -// authorization_endpoint: `http://localhost:${port}/oauth/auth.html`, -// // the token endpoint receives requests from synapse, -// // rather than the webapp, so needs to escape the docker container. -// token_endpoint: `http://host.testcontainers.internal:${port}/oauth/token`, -// userinfo_endpoint: `http://host.testcontainers.internal:${port}/oauth/userinfo`, -// client_id: "synapse", -// discover: false, -// scopes: ["profile"], -// skip_verification: true, -// client_auth_method: "none", -// user_mapping_provider: { -// config: { -// display_name_template: "{{ user.name }}", -// }, -// }, -// }, -// ], -// }); -// await use(container); -// server.stop(); -// }, -// }; +import { Fixtures, PlaywrightTestArgs } from "@playwright/test"; + +import { Fixtures as BaseFixtures } from "../../../element-web-test.ts"; +import { DendriteContainer, PineconeContainer } from "../../../testcontainers/dendrite.ts"; +import { Services } from "../../../services.ts"; + +type Fixture = PlaywrightTestArgs & Services & BaseFixtures; +export const dendriteHomeserver: Fixtures = { + _homeserver: async ({ request }, use) => { + const container = + process.env["PLAYWRIGHT_HOMESERVER"] === "dendrite" + ? new DendriteContainer(request) + : new PineconeContainer(request); + await use(container); + }, + homeserver: async ({ logger, network, _homeserver: homeserver }, use) => { + const container = await homeserver + .withNetwork(network) + .withNetworkAliases("homeserver") + .withLogConsumer(logger.getConsumer("dendrite")) + .start(); + + await use(container); + await container.stop(); + }, +}; export function isDendrite(): boolean { return process.env["PLAYWRIGHT_HOMESERVER"] === "dendrite" || process.env["PLAYWRIGHT_HOMESERVER"] === "pinecone"; diff --git a/playwright/services.ts b/playwright/services.ts index c05cb2d29dc..58fc21775ea 100644 --- a/playwright/services.ts +++ b/playwright/services.ts @@ -10,9 +10,10 @@ import mailhog from "mailhog"; import { GenericContainer, Network, StartedNetwork, StartedTestContainer, Wait } from "testcontainers"; import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql"; -import { StartedSynapseContainer, SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts"; +import { SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts"; import { ContainerLogger } from "./testcontainers/utils.ts"; import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts"; +import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts"; export interface Services { logger: ContainerLogger; @@ -24,8 +25,8 @@ export interface Services { mailhogClient: mailhog.API; synapseConfigOptions: SynapseConfigOptions; - _homeserver: SynapseContainer; - homeserver: StartedSynapseContainer; + _homeserver: HomeserverContainer; + homeserver: StartedHomeserverContainer; mas?: StartedMatrixAuthenticationServiceContainer; } diff --git a/playwright/testcontainers/HomeserverContainer.ts b/playwright/testcontainers/HomeserverContainer.ts new file mode 100644 index 00000000000..bbe075f2c95 --- /dev/null +++ b/playwright/testcontainers/HomeserverContainer.ts @@ -0,0 +1,19 @@ +/* +Copyright 2024 New Vector Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE files in the repository root for full details. +*/ + +import { AbstractStartedContainer, GenericContainer } from "testcontainers"; + +import { StartedSynapseContainer } from "./synapse.ts"; +import { HomeserverInstance } from "../plugins/homeserver"; + +export interface HomeserverContainer extends GenericContainer { + withConfigField(key: string, value: any): this; + withConfig(config: Partial): this; + start(): Promise; +} + +export interface StartedHomeserverContainer extends AbstractStartedContainer, HomeserverInstance {} diff --git a/playwright/testcontainers/dendrite.ts b/playwright/testcontainers/dendrite.ts index 141d96156b6..484b828b524 100644 --- a/playwright/testcontainers/dendrite.ts +++ b/playwright/testcontainers/dendrite.ts @@ -13,6 +13,7 @@ import { set } from "lodash"; import { randB64Bytes } from "../plugins/utils/rand.ts"; import { StartedSynapseContainer } from "./synapse.ts"; import { deepCopy } from "../plugins/utils/object.ts"; +import { HomeserverContainer } from "./HomeserverContainer.ts"; const DEFAULT_CONFIG = { version: 2, @@ -204,7 +205,7 @@ const DEFAULT_CONFIG = { ], }; -export class DendriteContainer extends GenericContainer { +export class DendriteContainer extends GenericContainer implements HomeserverContainer { private config: typeof DEFAULT_CONFIG; constructor( diff --git a/playwright/testcontainers/synapse.ts b/playwright/testcontainers/synapse.ts index a04041437f3..46a4bcb415c 100644 --- a/playwright/testcontainers/synapse.ts +++ b/playwright/testcontainers/synapse.ts @@ -13,8 +13,9 @@ import { set } from "lodash"; import { getFreePort } from "../plugins/utils/port.ts"; import { randB64Bytes } from "../plugins/utils/rand.ts"; -import { Credentials, HomeserverInstance } from "../plugins/homeserver"; +import { Credentials } from "../plugins/homeserver"; import { deepCopy } from "../plugins/utils/object.ts"; +import { HomeserverContainer, StartedHomeserverContainer } from "./HomeserverContainer.ts"; const TAG = "develop@sha256:17cc0a301447430624afb860276e5c13270ddeb99a3f6d1c6d519a20b1a8f650"; @@ -137,7 +138,7 @@ const DEFAULT_CONFIG = { export type SynapseConfigOptions = Partial; -export class SynapseContainer extends GenericContainer { +export class SynapseContainer extends GenericContainer implements HomeserverContainer { private config: typeof DEFAULT_CONFIG; constructor(private readonly request: APIRequestContext) { @@ -225,7 +226,7 @@ export class SynapseContainer extends GenericContainer { } } -export class StartedSynapseContainer extends AbstractStartedContainer implements HomeserverInstance { +export class StartedSynapseContainer extends AbstractStartedContainer implements StartedHomeserverContainer { private adminToken?: string; constructor(