This commit is contained in:
Michael Telatynski 2026-03-04 10:32:58 +00:00
parent fd4bb50a14
commit 225fe7c406
3 changed files with 61 additions and 22 deletions

View File

@ -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<TestFixtures, WorkerOptions & Services>({
],
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();
},

View File

@ -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<MasConfig>,
name = "mas",
): Promise<StartedMatrixAuthenticationServiceContainer> {
const container = await new MatrixAuthenticationServiceContainer(postgres)
.withNetwork(network)
.withNetworkAliases(name)
.withLogConsumer(logger.getConsumer(name))
.withConfig(config)
.start();
return container;
}

View File

@ -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<StartedPostgreSqlContainer> {
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;
}