Skip to content

Commit 5ccaa96

Browse files
committed
Add health check prior to teardown
1 parent 0606454 commit 5ccaa96

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

frontend/e2e/global-setup.playwright.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ async function globalSetup(config: FullConfig) {
77
console.log('Starting global setup for E2E tests...');
88

99
const e2eTestApi = `${process.env.FLAGSMITH_API_URL || Project.api}e2etests/teardown/`;
10+
const apiHealthUrl = `${process.env.FLAGSMITH_API_URL || Project.api}health`;
1011
const token = process.env.E2E_TEST_TOKEN
1112
? process.env.E2E_TEST_TOKEN
1213
: process.env[`E2E_TEST_TOKEN_${Project.env.toUpperCase()}`];
@@ -19,6 +20,30 @@ async function globalSetup(config: FullConfig) {
1920
'\n',
2021
);
2122

23+
// Wait for API to be ready (max 60 seconds)
24+
console.log('Waiting for API to be ready...');
25+
const maxWaitTime = 60000; // 60 seconds
26+
const startTime = Date.now();
27+
let apiReady = false;
28+
29+
while (!apiReady && Date.now() - startTime < maxWaitTime) {
30+
try {
31+
const healthRes = await fetch(apiHealthUrl);
32+
if (healthRes.ok) {
33+
apiReady = true;
34+
console.log('\n', '\x1b[32m', 'API is ready', '\x1b[0m', '\n');
35+
} else {
36+
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds before retry
37+
}
38+
} catch (error) {
39+
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds before retry
40+
}
41+
}
42+
43+
if (!apiReady) {
44+
console.error('\n', '\x1b[31m', 'API health check failed - continuing anyway', '\x1b[0m', '\n');
45+
}
46+
2247
// Initialize Flagsmith
2348
await flagsmith.init({
2449
api: Project.flagsmithClientAPI,

0 commit comments

Comments
 (0)