From 097d2296e01d6b1055f1d9a1a2c43c93addb0d02 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 25 Oct 2022 17:02:17 +0530 Subject: [PATCH] Make testing more reliable - Stop any running containers - Start dev server from playwright so that we don't keep spawning new node instances --- package.json | 2 +- playwright.config.ts | 24 +++++++++++++---------- playwright/plugins/dex/index.ts | 2 +- playwright/plugins/synapsedocker/index.ts | 2 +- scripts/test-app.sh | 19 ++++++++++++++++++ 5 files changed, 36 insertions(+), 13 deletions(-) create mode 100755 scripts/test-app.sh diff --git a/package.json b/package.json index 569354f0..002cc24a 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "build": "vite build && ./scripts/cleanup.sh", "build:sdk": "./scripts/sdk/build.sh", "watch:sdk": "./scripts/sdk/build.sh && yarn run vite build -c vite.sdk-lib-config.js --watch", - "test:app": "vite --port 3000 & playwright test" + "test:app": "./scripts/test-app.sh" }, "repository": { "type": "git", diff --git a/playwright.config.ts b/playwright.config.ts index 901e48d9..6fbb499b 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,16 +1,20 @@ -import type { PlaywrightTestConfig } from '@playwright/test'; +import type { PlaywrightTestConfig } from "@playwright/test"; const BASE_URL = process.env["BASE_URL"] ?? "http://127.0.0.1:3000"; const config: PlaywrightTestConfig = { - use: { - headless: false, - viewport: { width: 1280, height: 720 }, - ignoreHTTPSErrors: true, - video: 'on-first-retry', - baseURL: BASE_URL, - }, - testDir: "./playwright/tests", - globalSetup: require.resolve("./playwright/global-setup"), + use: { + headless: false, + viewport: { width: 1280, height: 720 }, + ignoreHTTPSErrors: true, + video: "on-first-retry", + baseURL: BASE_URL, + }, + testDir: "./playwright/tests", + globalSetup: require.resolve("./playwright/global-setup"), + webServer: { + command: "yarn start", + url: `${BASE_URL}/#/login`, + }, }; export default config; diff --git a/playwright/plugins/dex/index.ts b/playwright/plugins/dex/index.ts index 56605cf5..f45257fc 100644 --- a/playwright/plugins/dex/index.ts +++ b/playwright/plugins/dex/index.ts @@ -77,7 +77,7 @@ export async function dexStart(): Promise { console.log(`Starting dex with config dir ${dexCfg.configDir}...`); const dexId = await dockerRun({ image: "bitnami/dex:latest", - containerName: "dex", + containerName: "hydrogen-dex", dockerParams: [ "--rm", "-v", `${dexCfg.configDir}:/data`, diff --git a/playwright/plugins/synapsedocker/index.ts b/playwright/plugins/synapsedocker/index.ts index 1917aa85..56ffa214 100644 --- a/playwright/plugins/synapsedocker/index.ts +++ b/playwright/plugins/synapsedocker/index.ts @@ -108,7 +108,7 @@ export async function synapseStart(template: string): Promise { await dockerCreateNetwork({ networkName: "hydrogen" }); const synapseId = await dockerRun({ image: "matrixdotorg/synapse:develop", - containerName: `react-sdk-cypress-synapse-${crypto.randomBytes(4).toString("hex")}`, + containerName: `hydrogen-synapse`, dockerParams: [ "--rm", "-v", `${synCfg.configDir}:/data`, diff --git a/scripts/test-app.sh b/scripts/test-app.sh new file mode 100755 index 00000000..cfbd37a3 --- /dev/null +++ b/scripts/test-app.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Make sure docker is available +if ! docker info > /dev/null 2>&1; then + echo "You need to intall docker before you can run the tests!" + exit 1 +fi + +# Stop running containers +if docker stop hydrogen-synapse > /dev/null 2>&1; then + echo "Existing 'hydrogen-synapse' container stopped ✔" +fi + +if docker stop hydrogen-dex > /dev/null 2>&1; then + echo "Existing 'hydrogen-dex' container stopped ✔" +fi + +# Run playwright +yarn playwright test