Merge branch 't3chguy/flaky-tests-10jan2' of https://github.com/vector-im/element-web into t3chguy/flaky-tests-10jan
This commit is contained in:
@@ -79,7 +79,7 @@ test.use({
|
|||||||
The appropriate homeserver will be launched by the Playwright worker and reused for all tests which match the worker configuration.
|
The appropriate homeserver will be launched by the Playwright worker and reused for all tests which match the worker configuration.
|
||||||
Due to homeservers being reused between tests, please use unique names for any rooms put into the room directory as
|
Due to homeservers being reused between tests, please use unique names for any rooms put into the room directory as
|
||||||
they may be visible from other tests, the suggested approach is to use `testInfo.testId` within the name or lodash's uniqueId.
|
they may be visible from other tests, the suggested approach is to use `testInfo.testId` within the name or lodash's uniqueId.
|
||||||
We remove public rooms from the directory between tests but deleting users doesn't have a homeserver agnostic solution.
|
We remove public rooms from the room directory between tests but deleting users doesn't have a homeserver agnostic solution.
|
||||||
The logs from testcontainers will be attached to any reports output from Playwright.
|
The logs from testcontainers will be attached to any reports output from Playwright.
|
||||||
|
|
||||||
## Writing Tests
|
## Writing Tests
|
||||||
|
|||||||
@@ -7,22 +7,25 @@ Please see LICENSE files in the repository root for full details.
|
|||||||
|
|
||||||
import { test as base } from "@playwright/test";
|
import { test as base } from "@playwright/test";
|
||||||
import mailhog from "mailhog";
|
import mailhog from "mailhog";
|
||||||
import { GenericContainer, Network, StartedNetwork, StartedTestContainer, Wait } 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 { SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts";
|
||||||
import { ContainerLogger } from "./testcontainers/utils.ts";
|
import { ContainerLogger } from "./testcontainers/utils.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";
|
||||||
|
|
||||||
|
interface TestFixtures {
|
||||||
|
mailhogClient: mailhog.API;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Services {
|
export interface Services {
|
||||||
logger: ContainerLogger;
|
logger: ContainerLogger;
|
||||||
|
|
||||||
network: StartedNetwork;
|
network: StartedNetwork;
|
||||||
postgres: StartedPostgreSqlContainer;
|
postgres: StartedPostgreSqlContainer;
|
||||||
|
mailhog: StartedMailhogContainer;
|
||||||
mailhog: StartedTestContainer;
|
|
||||||
mailhogClient: mailhog.API;
|
|
||||||
|
|
||||||
synapseConfigOptions: SynapseConfigOptions;
|
synapseConfigOptions: SynapseConfigOptions;
|
||||||
_homeserver: HomeserverContainer<any>;
|
_homeserver: HomeserverContainer<any>;
|
||||||
@@ -30,7 +33,7 @@ export interface Services {
|
|||||||
mas?: StartedMatrixAuthenticationServiceContainer;
|
mas?: StartedMatrixAuthenticationServiceContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const test = base.extend<{}, Services>({
|
export const test = base.extend<TestFixtures, Services>({
|
||||||
logger: [
|
logger: [
|
||||||
// eslint-disable-next-line no-empty-pattern
|
// eslint-disable-next-line no-empty-pattern
|
||||||
async ({}, use) => {
|
async ({}, use) => {
|
||||||
@@ -79,24 +82,20 @@ export const test = base.extend<{}, Services>({
|
|||||||
|
|
||||||
mailhog: [
|
mailhog: [
|
||||||
async ({ logger, network }, use) => {
|
async ({ logger, network }, use) => {
|
||||||
const container = await new GenericContainer("mailhog/mailhog:latest")
|
const container = await new MailhogContainer()
|
||||||
.withNetwork(network)
|
.withNetwork(network)
|
||||||
.withNetworkAliases("mailhog")
|
.withNetworkAliases("mailhog")
|
||||||
.withExposedPorts(8025)
|
|
||||||
.withLogConsumer(logger.getConsumer("mailhog"))
|
.withLogConsumer(logger.getConsumer("mailhog"))
|
||||||
.withWaitStrategy(Wait.forListeningPorts())
|
|
||||||
.start();
|
.start();
|
||||||
await use(container);
|
await use(container);
|
||||||
await container.stop();
|
await container.stop();
|
||||||
},
|
},
|
||||||
{ scope: "worker" },
|
{ scope: "worker" },
|
||||||
],
|
],
|
||||||
mailhogClient: [
|
mailhogClient: async ({ mailhog: container }, use) => {
|
||||||
async ({ mailhog: container }, use) => {
|
await use(container.client);
|
||||||
await use(mailhog({ host: container.getHost(), port: container.getMappedPort(8025) }));
|
await container.client.deleteAll();
|
||||||
},
|
},
|
||||||
{ scope: "worker" },
|
|
||||||
],
|
|
||||||
|
|
||||||
synapseConfigOptions: [{}, { option: true, scope: "worker" }],
|
synapseConfigOptions: [{}, { option: true, scope: "worker" }],
|
||||||
_homeserver: [
|
_homeserver: [
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
30
playwright/testcontainers/mailhog.ts
Normal file
30
playwright/testcontainers/mailhog.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
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, StartedTestContainer, Wait } from "testcontainers";
|
||||||
|
import mailhog from "mailhog";
|
||||||
|
|
||||||
|
export class MailhogContainer extends GenericContainer {
|
||||||
|
constructor() {
|
||||||
|
super("mailhog/mailhog:latest");
|
||||||
|
|
||||||
|
this.withExposedPorts(8025).withWaitStrategy(Wait.forListeningPorts());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async start(): Promise<StartedMailhogContainer> {
|
||||||
|
return new StartedMailhogContainer(await super.start());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class StartedMailhogContainer extends AbstractStartedContainer {
|
||||||
|
public readonly client: mailhog.API;
|
||||||
|
|
||||||
|
constructor(container: StartedTestContainer) {
|
||||||
|
super(container);
|
||||||
|
this.client = mailhog({ host: container.getHost(), port: container.getMappedPort(8025) });
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user