Skip to content

Commit 3c22e5d

Browse files
authored
Switch to mailpit for Playwright tests (#29108)
* Switch to mailpit for Playwright tests as mailhog is unsupported and lacks arm64 support Signed-off-by: Michael Telatynski <[email protected]> * Fix yarn.lock Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * delint Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent f29ce94 commit 3c22e5d

File tree

12 files changed

+62
-49
lines changed

12 files changed

+62
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
"jsqr": "^1.4.0",
257257
"knip": "^5.36.2",
258258
"lint-staged": "^15.0.2",
259-
"mailhog": "^4.16.0",
259+
"mailpit-api": "^1.0.5",
260260
"matrix-web-i18n": "^3.2.1",
261261
"mini-css-extract-plugin": "2.9.2",
262262
"minimist": "^1.2.6",

playwright/e2e/crypto/backups-mas.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ test.use(masHomeserver);
1919
test.describe("Encryption state after registration", () => {
2020
test.skip(isDendrite, "does not yet support MAS");
2121

22-
test("Key backup is enabled by default", async ({ page, mailhogClient, app }, testInfo) => {
22+
test("Key backup is enabled by default", async ({ page, mailpitClient, app }, testInfo) => {
2323
await page.goto("/#/login");
2424
await page.getByRole("button", { name: "Continue" }).click();
25-
await registerAccountMas(page, mailhogClient, `alice_${testInfo.testId}`, "[email protected]", "Pa$sW0rD!");
25+
await registerAccountMas(page, mailpitClient, `alice_${testInfo.testId}`, "[email protected]", "Pa$sW0rD!");
2626

2727
await app.settings.openUserSettings("Security & Privacy");
2828
await expect(page.getByText("This session is backing up your keys.")).toBeVisible();
2929
});
3030

31-
test("user is prompted to set up recovery", async ({ page, mailhogClient, app }, testInfo) => {
31+
test("user is prompted to set up recovery", async ({ page, mailpitClient, app }, testInfo) => {
3232
await page.goto("/#/login");
3333
await page.getByRole("button", { name: "Continue" }).click();
34-
await registerAccountMas(page, mailhogClient, `alice_${testInfo.testId}`, "[email protected]", "Pa$sW0rD!");
34+
await registerAccountMas(page, mailpitClient, `alice_${testInfo.testId}`, "[email protected]", "Pa$sW0rD!");
3535

3636
await page.getByRole("button", { name: "Add room" }).click();
3737
await page.getByRole("menuitem", { name: "New room" }).click();
@@ -47,7 +47,7 @@ test.describe("Key backup reset from elsewhere", () => {
4747

4848
test("Key backup is disabled when reset from elsewhere", async ({
4949
page,
50-
mailhogClient,
50+
mailpitClient,
5151
request,
5252
homeserver,
5353
}, testInfo) => {
@@ -60,7 +60,7 @@ test.describe("Key backup reset from elsewhere", () => {
6060

6161
await page.goto("/#/login");
6262
await page.getByRole("button", { name: "Continue" }).click();
63-
await registerAccountMas(page, mailhogClient, testUsername, "[email protected]", testPassword);
63+
await registerAccountMas(page, mailpitClient, testUsername, "[email protected]", testPassword);
6464

6565
await page.getByRole("button", { name: "Add room" }).click();
6666
await page.getByRole("menuitem", { name: "New room" }).click();

playwright/e2e/oidc/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { API, Messages } from "mailhog";
9+
import { MailpitClient } from "mailpit-api";
1010
import { Page } from "@playwright/test";
1111

1212
import { expect } from "../../element-web-test";
1313

1414
export async function registerAccountMas(
1515
page: Page,
16-
mailhog: API,
16+
mailpit: MailpitClient,
1717
username: string,
1818
email: string,
1919
password: string,
@@ -27,13 +27,13 @@ export async function registerAccountMas(
2727
await page.getByRole("textbox", { name: "Confirm Password" }).fill(password);
2828
await page.getByRole("button", { name: "Continue" }).click();
2929

30-
let messages: Messages;
30+
let code: string;
3131
await expect(async () => {
32-
messages = await mailhog.messages();
33-
expect(messages.items).toHaveLength(1);
32+
const messages = await mailpit.listMessages();
33+
expect(messages.messages[0].To[0].Address).toEqual(email);
34+
const text = await mailpit.renderMessageText(messages.messages[0].ID);
35+
[, code] = text.match(/Your verification code to confirm this email address is: (\d{6})/);
3436
}).toPass();
35-
expect(messages.items[0].to).toEqual(`${username} <${email}>`);
36-
const [, code] = messages.items[0].text.match(/Your verification code to confirm this email address is: (\d{6})/);
3737

3838
await page.getByRole("textbox", { name: "6-digit code" }).fill(code);
3939
await page.getByRole("button", { name: "Continue" }).click();

playwright/e2e/oidc/oidc-native.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test.describe("OIDC Native", { tag: ["@no-firefox", "@no-webkit"] }, () => {
1919
context,
2020
page,
2121
homeserver,
22-
mailhogClient,
22+
mailpitClient,
2323
mas,
2424
}, testInfo) => {
2525
await page.clock.install();
@@ -33,7 +33,7 @@ test.describe("OIDC Native", { tag: ["@no-firefox", "@no-webkit"] }, () => {
3333
await page.getByRole("button", { name: "Continue" }).click();
3434

3535
const userId = `alice_${testInfo.testId}`;
36-
await registerAccountMas(page, mailhogClient, userId, "[email protected]", "Pa$sW0rD!");
36+
await registerAccountMas(page, mailpitClient, userId, "[email protected]", "Pa$sW0rD!");
3737

3838
// Eventually, we should end up at the home screen.
3939
await expect(page).toHaveURL(/\/#\/home$/, { timeout: 10000 });

playwright/e2e/register/email.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test.describe("Email Registration", async () => {
3434
test(
3535
"registers an account and lands on the home page",
3636
{ tag: "@screenshot" },
37-
async ({ page, mailhogClient, request, checkA11y }) => {
37+
async ({ page, mailpitClient, request, checkA11y }) => {
3838
await expect(page.getByRole("textbox", { name: "Username" })).toBeVisible();
3939
// Hide the server text as it contains the randomly allocated Homeserver port
4040
const screenshotOptions = { mask: [page.locator(".mx_ServerPicker_server")] };
@@ -51,10 +51,11 @@ test.describe("Email Registration", async () => {
5151

5252
await expect(page.getByText("An error was encountered when sending the email")).not.toBeVisible();
5353

54-
const messages = await mailhogClient.messages();
55-
expect(messages.items).toHaveLength(1);
56-
expect(messages.items[0].to).toEqual("[email protected]");
57-
const [emailLink] = messages.items[0].text.match(/http.+/);
54+
const messages = await mailpitClient.listMessages();
55+
expect(messages.messages).toHaveLength(1);
56+
expect(messages.messages[0].To[0].Address).toEqual("[email protected]");
57+
const text = await mailpitClient.renderMessageText(messages.messages[0].ID);
58+
const [emailLink] = text.match(/http.+/);
5859
await request.get(emailLink); // "Click" the link in the email
5960

6061
await expect(page.getByText("Welcome alice")).toBeVisible();

playwright/plugins/homeserver/synapse/consentHomeserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { Fixtures } from "../../../element-web-test.ts";
1010

1111
export const consentHomeserver: Fixtures = {
1212
_homeserver: [
13-
async ({ _homeserver: container, mailhog }, use) => {
13+
async ({ _homeserver: container, mailpit }, use) => {
1414
container
1515
.withCopyDirectoriesToContainer([
1616
{ source: "playwright/plugins/homeserver/synapse/res", target: "/data/res" },
1717
])
1818
.withConfig({
1919
email: {
2020
enable_notifs: false,
21-
smtp_host: "mailhog",
21+
smtp_host: "mailpit",
2222
smtp_port: 1025,
2323
smtp_user: "username",
2424
smtp_pass: "password",

playwright/plugins/homeserver/synapse/emailHomeserver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { Fixtures } from "../../../element-web-test.ts";
1010

1111
export const emailHomeserver: Fixtures = {
1212
_homeserver: [
13-
async ({ _homeserver: container, mailhog }, use) => {
13+
async ({ _homeserver: container, mailpit }, use) => {
1414
container.withConfig({
1515
enable_registration_without_verification: undefined,
1616
disable_msisdn_registration: undefined,
1717
registrations_require_3pid: ["email"],
1818
email: {
19-
smtp_host: "mailhog",
19+
smtp_host: "mailpit",
2020
smtp_port: 1025,
2121
notif_from: "Your Friendly %(app)s homeserver <[email protected]>",
2222
app_name: "my_branded_matrix_server",

playwright/plugins/homeserver/synapse/masHomeserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Fixtures } from "../../../element-web-test.ts";
1111

1212
export const masHomeserver: Fixtures = {
1313
mas: [
14-
async ({ _homeserver: homeserver, logger, network, postgres, mailhog }, use) => {
14+
async ({ _homeserver: homeserver, logger, network, postgres, mailpit }, use) => {
1515
const config = {
1616
clients: [
1717
{

playwright/services.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { test as base } from "@playwright/test";
9-
import mailhog from "mailhog";
9+
import { MailpitClient } from "mailpit-api";
1010
import { Network, StartedNetwork } from "testcontainers";
1111
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";
1212

1313
import { SynapseConfig, SynapseContainer } from "./testcontainers/synapse.ts";
1414
import { Logger } from "./logger.ts";
1515
import { StartedMatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts";
1616
import { HomeserverContainer, StartedHomeserverContainer } from "./testcontainers/HomeserverContainer.ts";
17-
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailhog.ts";
17+
import { MailhogContainer, StartedMailhogContainer } from "./testcontainers/mailpit.ts";
1818
import { OAuthServer } from "./plugins/oauth_server";
1919
import { DendriteContainer, PineconeContainer } from "./testcontainers/dendrite.ts";
2020
import { HomeserverType } from "./plugins/homeserver";
2121

2222
export interface TestFixtures {
23-
mailhogClient: mailhog.API;
23+
mailpitClient: MailpitClient;
2424
}
2525

2626
export interface Services {
2727
logger: Logger;
2828

2929
network: StartedNetwork;
3030
postgres: StartedPostgreSqlContainer;
31-
mailhog: StartedMailhogContainer;
31+
mailpit: StartedMailhogContainer;
3232

3333
synapseConfig: SynapseConfig;
3434
_homeserver: HomeserverContainer<any>;
@@ -90,20 +90,20 @@ export const test = base.extend<TestFixtures, Services & Options>({
9090
{ scope: "worker" },
9191
],
9292

93-
mailhog: [
93+
mailpit: [
9494
async ({ logger, network }, use) => {
9595
const container = await new MailhogContainer()
9696
.withNetwork(network)
97-
.withNetworkAliases("mailhog")
98-
.withLogConsumer(logger.getConsumer("mailhog"))
97+
.withNetworkAliases("mailpit")
98+
.withLogConsumer(logger.getConsumer("mailpit"))
9999
.start();
100100
await use(container);
101101
await container.stop();
102102
},
103103
{ scope: "worker" },
104104
],
105-
mailhogClient: async ({ mailhog: container }, use) => {
106-
await container.client.deleteAll();
105+
mailpitClient: async ({ mailpit: container }, use) => {
106+
await container.client.deleteMessages();
107107
await use(container.client);
108108
},
109109

playwright/testcontainers/mailhog.ts renamed to playwright/testcontainers/mailpit.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { AbstractStartedContainer, GenericContainer, StartedTestContainer, Wait } from "testcontainers";
9-
import mailhog from "mailhog";
9+
import { MailpitClient } from "mailpit-api";
1010

1111
export class MailhogContainer extends GenericContainer {
1212
constructor() {
13-
super("mailhog/mailhog:latest");
13+
super("axllent/mailpit:latest");
1414

15-
this.withExposedPorts(8025).withWaitStrategy(Wait.forListeningPorts());
15+
this.withExposedPorts(8025).withWaitStrategy(Wait.forListeningPorts()).withEnvironment({
16+
MP_SMTP_AUTH_ALLOW_INSECURE: "true",
17+
MP_SMTP_AUTH_ACCEPT_ANY: "true",
18+
});
1619
}
1720

1821
public override async start(): Promise<StartedMailhogContainer> {
@@ -21,10 +24,10 @@ export class MailhogContainer extends GenericContainer {
2124
}
2225

2326
export class StartedMailhogContainer extends AbstractStartedContainer {
24-
public readonly client: mailhog.API;
27+
public readonly client: MailpitClient;
2528

2629
constructor(container: StartedTestContainer) {
2730
super(container);
28-
this.client = mailhog({ host: container.getHost(), port: container.getMappedPort(8025) });
31+
this.client = new MailpitClient(`http://${container.getHost()}:${container.getMappedPort(8025)}`);
2932
}
3033
}

0 commit comments

Comments
 (0)