Switch to TestContainers for manging services in Playwright (#28860)
* Switch to TestContainers for manging services in Playwright Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Flip fixture dependency order Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove mas dep Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update matrix-authentication-service in Playwright tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix SMTP port Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Comments Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Strip ansi from playwright logs to make them more readable Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Actually do the update Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Remove access to homeserver.config.baseUrl field in favour of homeserver.baseUrl Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Use sane default_server_config and specify server.invalid in the specific tests which demand it Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix mas run Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * break cycle Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * typo Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * prettier Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Wire up basics of dendriteHomeserver Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
66bbb84e56
commit
f75d1f5a5e
@@ -6,24 +6,20 @@ 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.
|
||||
*/
|
||||
|
||||
import { test as base, expect as baseExpect, Locator, Page, ExpectMatcherState, ElementHandle } from "@playwright/test";
|
||||
import { expect as baseExpect, Locator, Page, ExpectMatcherState, ElementHandle } from "@playwright/test";
|
||||
import { sanitizeForFilePath } from "playwright-core/lib/utils";
|
||||
import AxeBuilder from "@axe-core/playwright";
|
||||
import _ from "lodash";
|
||||
import { basename, extname } from "node:path";
|
||||
import { extname } from "node:path";
|
||||
|
||||
import type mailhog from "mailhog";
|
||||
import type { IConfigOptions } from "../src/IConfigOptions";
|
||||
import { Credentials, Homeserver, HomeserverInstance, StartHomeserverOpts } from "./plugins/homeserver";
|
||||
import { Synapse } from "./plugins/homeserver/synapse";
|
||||
import { Dendrite, Pinecone } from "./plugins/homeserver/dendrite";
|
||||
import { Instance, MailHogServer } from "./plugins/mailhog";
|
||||
import { Credentials } from "./plugins/homeserver";
|
||||
import { ElementAppPage } from "./pages/ElementAppPage";
|
||||
import { OAuthServer } from "./plugins/oauth_server";
|
||||
import { Crypto } from "./pages/crypto";
|
||||
import { Toasts } from "./pages/toasts";
|
||||
import { Bot, CreateBotOpts } from "./pages/bot";
|
||||
import { Webserver } from "./plugins/webserver";
|
||||
import { test as base } from "./services.ts";
|
||||
|
||||
// Enable experimental service worker support
|
||||
// See https://playwright.dev/docs/service-workers-experimental#how-to-enable
|
||||
@@ -58,14 +54,6 @@ export interface Fixtures {
|
||||
*/
|
||||
config: typeof CONFIG_JSON;
|
||||
|
||||
/**
|
||||
* The options with which to run the {@link #homeserver} fixture.
|
||||
*/
|
||||
startHomeserverOpts: StartHomeserverOpts | string;
|
||||
|
||||
homeserver: HomeserverInstance;
|
||||
oAuthServer: { port: number };
|
||||
|
||||
/**
|
||||
* The displayname to use for the user registered in {@link #credentials}.
|
||||
*
|
||||
@@ -103,7 +91,6 @@ export interface Fixtures {
|
||||
*/
|
||||
app: ElementAppPage;
|
||||
|
||||
mailhog: { api: mailhog.API; instance: Instance };
|
||||
crypto: Crypto;
|
||||
room?: { roomId: string };
|
||||
toasts: Toasts;
|
||||
@@ -149,45 +136,6 @@ export const test = base.extend<Fixtures>({
|
||||
await use(page);
|
||||
},
|
||||
|
||||
startHomeserverOpts: "default",
|
||||
homeserver: async ({ request, startHomeserverOpts: opts }, use, testInfo) => {
|
||||
if (typeof opts === "string") {
|
||||
opts = { template: opts };
|
||||
}
|
||||
|
||||
let server: Homeserver;
|
||||
const homeserverName = process.env["PLAYWRIGHT_HOMESERVER"];
|
||||
switch (homeserverName) {
|
||||
case "dendrite":
|
||||
server = new Dendrite(request);
|
||||
break;
|
||||
case "pinecone":
|
||||
server = new Pinecone(request);
|
||||
break;
|
||||
default:
|
||||
server = new Synapse(request);
|
||||
}
|
||||
|
||||
await use(await server.start(opts));
|
||||
const logs = await server.stop();
|
||||
|
||||
if (testInfo.status !== "passed") {
|
||||
for (const path of logs) {
|
||||
await testInfo.attach(`homeserver-${basename(path)}`, {
|
||||
path,
|
||||
contentType: "text/plain",
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
oAuthServer: async ({}, use) => {
|
||||
const server = new OAuthServer();
|
||||
const port = server.start();
|
||||
await use({ port });
|
||||
server.stop();
|
||||
},
|
||||
|
||||
displayName: undefined,
|
||||
credentials: async ({ homeserver, displayName: testDisplayName }, use) => {
|
||||
const names = ["Alice", "Bob", "Charlie", "Daniel", "Eve", "Frank", "Grace", "Hannah", "Isaac", "Judy"];
|
||||
@@ -216,8 +164,14 @@ export const test = base.extend<Fixtures>({
|
||||
window.localStorage.setItem("mx_has_pickle_key", "false");
|
||||
window.localStorage.setItem("mx_has_access_token", "true");
|
||||
|
||||
// Ensure the language is set to a consistent value
|
||||
window.localStorage.setItem("mx_local_settings", '{"language":"en"}');
|
||||
window.localStorage.setItem(
|
||||
"mx_local_settings",
|
||||
JSON.stringify({
|
||||
...JSON.parse(window.localStorage.getItem("mx_local_settings") || "{}"),
|
||||
// Ensure the language is set to a consistent value
|
||||
language: "en",
|
||||
}),
|
||||
);
|
||||
},
|
||||
{ baseUrl: homeserver.baseUrl, credentials },
|
||||
);
|
||||
@@ -264,14 +218,6 @@ export const test = base.extend<Fixtures>({
|
||||
await use(bot);
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
mailhog: async ({}, use) => {
|
||||
const mailhog = new MailHogServer();
|
||||
const instance = await mailhog.start();
|
||||
await use(instance);
|
||||
await mailhog.stop();
|
||||
},
|
||||
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
webserver: async ({}, use) => {
|
||||
const webserver = new Webserver();
|
||||
|
||||
Reference in New Issue
Block a user