diff --git a/packages/element-web-playwright-common/src/fixtures/services.ts b/packages/element-web-playwright-common/src/fixtures/services.ts index d4256c6213..de5e9af680 100644 --- a/packages/element-web-playwright-common/src/fixtures/services.ts +++ b/packages/element-web-playwright-common/src/fixtures/services.ts @@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details. import { type MailpitClient } from "mailpit-api"; import { Network, type StartedNetwork } from "testcontainers"; -import { PostgreSqlContainer, type StartedPostgreSqlContainer } from "@testcontainers/postgresql"; +import { type StartedPostgreSqlContainer } from "@testcontainers/postgresql"; import { type SynapseConfig, @@ -22,6 +22,7 @@ import { Logger } from "../utils/logger.js"; // We want to avoid using `mergeTests` in index.ts because it drops useful type information about the fixtures. Instead, // we add `axe` into our fixture suite by using its `test` as a base, so that there is a linear hierarchy. import { test as base } from "./axe.js"; +import { makePostgres } from "../testcontainers/postgres.js"; /** * Test-scoped fixtures available in the test @@ -101,27 +102,7 @@ export const test = base.extend({ ], postgres: [ async ({ logger, network }, use) => { - const container = await new PostgreSqlContainer("postgres:13.3-alpine") - .withNetwork(network) - .withNetworkAliases("postgres") - .withLogConsumer(logger.getConsumer("postgres")) - .withTmpFs({ - "/dev/shm/pgdata/data": "", - }) - .withEnvironment({ - PG_DATA: "/dev/shm/pgdata/data", - }) - .withCommand([ - "-c", - "shared_buffers=128MB", - "-c", - `fsync=off`, - "-c", - `synchronous_commit=off`, - "-c", - "full_page_writes=off", - ]) - .start(); + const container = await makePostgres(network, logger); await use(container); await container.stop(); }, diff --git a/packages/element-web-playwright-common/src/testcontainers/mas.ts b/packages/element-web-playwright-common/src/testcontainers/mas.ts index 430875797b..8e64db59f8 100644 --- a/packages/element-web-playwright-common/src/testcontainers/mas.ts +++ b/packages/element-web-playwright-common/src/testcontainers/mas.ts @@ -11,6 +11,7 @@ import { type StartedTestContainer, Wait, type ExecResult, + type StartedNetwork, } from "testcontainers"; import { type StartedPostgreSqlContainer } from "@testcontainers/postgresql"; import * as YAML from "yaml"; @@ -23,6 +24,7 @@ import { type Credentials } from "../utils/api.js"; // curl -sL https://element-hq.github.io/matrix-authentication-service/config.schema.json \ // | npx json-schema-to-typescript -o packages/element-web-playwright-common/src/testconainers/mas-config.ts import type { RootConfig as MasConfig } from "./mas-config.js"; +import type { Logger } from "../utils/logger.js"; export { type MasConfig }; @@ -349,3 +351,19 @@ export class StartedMatrixAuthenticationServiceContainer extends AbstractStarted await this.manage("add-email", username, address); } } + +export async function makeMas( + postgres: StartedPostgreSqlContainer, + network: StartedNetwork, + logger: Logger, + config: Partial, + name = "mas", +): Promise { + const container = await new MatrixAuthenticationServiceContainer(postgres) + .withNetwork(network) + .withNetworkAliases(name) + .withLogConsumer(logger.getConsumer(name)) + .withConfig(config) + .start(); + return container; +} diff --git a/packages/element-web-playwright-common/src/testcontainers/postgres.ts b/packages/element-web-playwright-common/src/testcontainers/postgres.ts new file mode 100644 index 0000000000..0dd0eab27d --- /dev/null +++ b/packages/element-web-playwright-common/src/testcontainers/postgres.ts @@ -0,0 +1,40 @@ +/* +Copyright 2026 Element Creations Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +Please see LICENSE files in the repository root for full details. +*/ + +import { PostgreSqlContainer, type StartedPostgreSqlContainer } from "@testcontainers/postgresql"; +import { type StartedNetwork } from "testcontainers"; + +import { type Logger } from "../utils/logger.js"; + +export async function makePostgres( + network: StartedNetwork, + logger: Logger, + name = "postgres", +): Promise { + const container = await new PostgreSqlContainer("postgres:13.3-alpine") + .withNetwork(network) + .withNetworkAliases(name) + .withLogConsumer(logger.getConsumer(name)) + .withTmpFs({ + "/dev/shm/pgdata/data": "", + }) + .withEnvironment({ + PG_DATA: "/dev/shm/pgdata/data", + }) + .withCommand([ + "-c", + "shared_buffers=128MB", + "-c", + `fsync=off`, + "-c", + `synchronous_commit=off`, + "-c", + "full_page_writes=off", + ]) + .start(); + return container; +}