diff --git a/playwright.config.ts b/playwright.config.ts index 6d510c8d68d..ccbb79d2d84 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -38,7 +38,8 @@ export default defineConfig({ ], webServer: { - url: 'http://127.0.0.1:8089', + // Don't set `url` as it would take precedence over `wait.stdout` and tests start too early + // url: 'http://127.0.0.1:8089', // Starts the Nextcloud docker container command: 'npm run start:nextcloud', // we use sigterm to notify the script to stop the container @@ -47,7 +48,8 @@ export default defineConfig({ signal: 'SIGTERM', timeout: 10000, }, - reuseExistingServer: !process.env.CI, + // `start-nextcloud-server.mjs` only starts the server if not reachable yet. + reuseExistingServer: false, stderr: 'pipe', stdout: 'pipe', // max. 5 minutes for creating the container diff --git a/playwright/start-nextcloud-server.mjs b/playwright/start-nextcloud-server.mjs index e36cdaedaa8..e8ca197e355 100644 --- a/playwright/start-nextcloud-server.mjs +++ b/playwright/start-nextcloud-server.mjs @@ -12,6 +12,15 @@ import { import { readFileSync } from 'fs' import { execSync } from 'node:child_process' +async function isServerRunning() { + try { + const res = await fetch('http://127.0.0.1:8089/status.php') + return res.ok + } catch { + return false + } +} + async function start() { const appinfo = readFileSync('appinfo/info.xml').toString() const maxVersion = appinfo.match( @@ -41,9 +50,14 @@ process.on('SIGTERM', stop) process.on('SIGINT', stop) // Start the Nextcloud docker container -const ip = await start() -await waitOnNextcloud(ip) -await configureNextcloud(['text', 'viewer']) +if (await isServerRunning()) { + // eslint-disable-next-line no-console + console.log('└─ Nextcloud is now ready to use') +} else { + const ip = await start() + await waitOnNextcloud(ip) + await configureNextcloud(['text', 'viewer']) +} // Idle to wait for shutdown while (true) {