Fix flaky playwright tests (#28984)
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1a21b718d8
commit
540580504d
@@ -6,20 +6,31 @@ 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 { Fixtures } from "@playwright/test";
|
||||
import { Fixtures, PlaywrightTestArgs } from "@playwright/test";
|
||||
import { TestContainers } from "testcontainers";
|
||||
|
||||
import { Services } from "../../../services.ts";
|
||||
import { OAuthServer } from "../../oauth_server";
|
||||
|
||||
export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
||||
_homeserver: [
|
||||
async ({ _homeserver: container }, use) => {
|
||||
export const legacyOAuthHomeserver: Fixtures<PlaywrightTestArgs, Services, PlaywrightTestArgs> = {
|
||||
oAuthServer: [
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
async ({}, use) => {
|
||||
const server = new OAuthServer();
|
||||
const port = server.start();
|
||||
|
||||
await use(server);
|
||||
server.stop();
|
||||
},
|
||||
{ scope: "worker" },
|
||||
],
|
||||
context: async ({ context, oAuthServer }, use, testInfo) => {
|
||||
oAuthServer.onTestStarted(testInfo);
|
||||
await use(context);
|
||||
},
|
||||
_homeserver: [
|
||||
async ({ oAuthServer, _homeserver: homeserver }, use) => {
|
||||
const port = oAuthServer.start();
|
||||
await TestContainers.exposeHostPorts(port);
|
||||
container.withConfig({
|
||||
homeserver.withConfig({
|
||||
oidc_providers: [
|
||||
{
|
||||
idp_id: "test",
|
||||
@@ -43,8 +54,8 @@ export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
||||
},
|
||||
],
|
||||
});
|
||||
await use(container);
|
||||
server.stop();
|
||||
|
||||
await use(homeserver);
|
||||
},
|
||||
{ scope: "worker" },
|
||||
],
|
||||
|
||||
@@ -9,12 +9,21 @@ Please see LICENSE files in the repository root for full details.
|
||||
import http from "http";
|
||||
import express from "express";
|
||||
import { AddressInfo } from "net";
|
||||
import { TestInfo } from "@playwright/test";
|
||||
|
||||
import { randB64Bytes } from "../utils/rand.ts";
|
||||
|
||||
export class OAuthServer {
|
||||
private server?: http.Server;
|
||||
private sub?: string;
|
||||
|
||||
public onTestStarted(testInfo: TestInfo): void {
|
||||
this.sub = testInfo.testId;
|
||||
}
|
||||
|
||||
public start(): number {
|
||||
if (this.server) this.stop();
|
||||
const token = randB64Bytes(16);
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -28,7 +37,7 @@ export class OAuthServer {
|
||||
const code = req.body.code;
|
||||
if (code === "valid_auth_code") {
|
||||
res.send({
|
||||
access_token: "oauth_access_token",
|
||||
access_token: token,
|
||||
token_type: "Bearer",
|
||||
expires_in: "3600",
|
||||
});
|
||||
@@ -43,7 +52,7 @@ export class OAuthServer {
|
||||
|
||||
// return an OAuth2 user info object
|
||||
res.send({
|
||||
sub: "alice",
|
||||
sub: this.sub,
|
||||
name: "Alice",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user