Skip to content

Commit 9d1e48a

Browse files
kyle-ssgclaude
andcommitted
Simplify E2E global setup and require auth token
- Refactor teardown logic to always require token (remove E2E_LOCAL/E2E_DEV special cases) - Add E2E env vars to docker-compose.yml for local testing - Use private-cloud image for enterprise test support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0d1fd77 commit 9d1e48a

3 files changed

Lines changed: 45 additions & 53 deletions

File tree

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
start_period: 20s
2222

2323
flagsmith:
24-
image: docker.flagsmith.com/flagsmith/flagsmith:latest
24+
image: flagsmith/flagsmith-private-cloud:latest
2525
environment:
2626
# All environments variables are available here:
2727
# API: https://docs.flagsmith.com/deployment/locally-api#environment-variables
@@ -41,6 +41,10 @@ services:
4141
TASK_RUN_METHOD: TASK_PROCESSOR # other options are: SYNCHRONOUSLY, SEPARATE_THREAD (default)
4242
PROMETHEUS_ENABLED: 'true'
4343

44+
# E2E Testing
45+
E2E_TEST_AUTH_TOKEN: 'some-token'
46+
ENABLE_FE_E2E: 'true'
47+
4448
# Uncomment if you want to enable Google OAuth. Note this does not turn Google OAuth on. You still need to use
4549
# Flagsmith on Flagsmith to enable it - https://docs.flagsmith.com/deployment/#oauth_google
4650
# DJANGO_SECURE_CROSS_ORIGIN_OPENER_POLICY: 'same-origin-allow-popups'
@@ -63,7 +67,7 @@ services:
6367
# The flagsmith_processor service is only needed if TASK_RUN_METHOD set to TASK_PROCESSOR
6468
# in the application environment
6569
flagsmith-task-processor:
66-
image: docker.flagsmith.com/flagsmith/flagsmith:latest
70+
image: flagsmith/flagsmith-private-cloud:latest
6771
environment:
6872
DATABASE_URL: postgresql://postgres:password@postgres:5432/flagsmith
6973
USE_POSTGRES_FOR_ANALYTICS: 'true'

frontend/e2e/global-setup.playwright.ts

Lines changed: 38 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,53 @@ async function globalSetup(config: FullConfig) {
3636
});
3737

3838
// Teardown previous test data with retry logic
39-
if (token) {
40-
const maxAttempts = 3;
41-
const delayMs = 2000;
42-
let teardownSuccess = false;
39+
if (!token) {
40+
const errorMsg = 'e2e teardown failed - no available token (set E2E_TEST_TOKEN or E2E_TEST_TOKEN_<ENV>)';
41+
console.error('\n', '\x1b[31m', errorMsg, '\x1b[0m', '\n');
42+
throw new Error(errorMsg);
43+
}
4344

44-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
45-
if (attempt > 0) {
46-
console.log(`\x1b[33m%s\x1b[0m`, `Retrying teardown (attempt ${attempt + 1}/${maxAttempts})...`);
47-
await new Promise(resolve => setTimeout(resolve, delayMs));
48-
}
45+
const maxAttempts = 3;
46+
const delayMs = 2000;
47+
48+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
49+
if (attempt > 0) {
50+
console.log(`\x1b[33m%s\x1b[0m`, `Retrying teardown (attempt ${attempt + 1}/${maxAttempts})...`);
51+
await new Promise(resolve => setTimeout(resolve, delayMs));
52+
}
4953

50-
try {
51-
const res = await fetch(e2eTestApi, {
52-
body: JSON.stringify({}),
53-
headers: {
54-
'Accept': 'application/json',
55-
'Content-Type': 'application/json',
56-
'X-E2E-Test-Auth-Token': token.trim(),
57-
},
58-
method: 'POST',
59-
});
54+
try {
55+
const res = await fetch(e2eTestApi, {
56+
body: JSON.stringify({}),
57+
headers: {
58+
'Accept': 'application/json',
59+
'Content-Type': 'application/json',
60+
'X-E2E-Test-Auth-Token': token.trim(),
61+
},
62+
method: 'POST',
63+
});
6064

61-
if (res.ok) {
62-
console.log('\n', '\x1b[32m', 'e2e teardown successful', '\x1b[0m', '\n');
63-
teardownSuccess = true;
64-
break;
65-
} else {
66-
console.error('\x1b[31m%s\x1b[0m', `✗ E2E teardown failed: ${res.status}`);
67-
if (attempt < maxAttempts - 1) {
68-
console.log('');
69-
}
70-
}
71-
} catch (error) {
72-
console.error('\x1b[31m%s\x1b[0m', `✗ E2E teardown error: ${error.message || String(error)}`);
73-
if (attempt < maxAttempts - 1) {
74-
console.log('');
75-
}
65+
if (res.ok) {
66+
console.log('\n', '\x1b[32m', 'e2e teardown successful', '\x1b[0m', '\n');
67+
console.log('Starting E2E tests');
68+
return;
7669
}
77-
}
7870

79-
if (!teardownSuccess) {
80-
const errorMsg = `e2e teardown failed after ${maxAttempts} attempts`;
81-
console.error('\n', '\x1b[31m', errorMsg, '\x1b[0m', '\n');
82-
if (process.env.E2E_LOCAL !== 'true' && process.env.E2E_DEV !== 'true') {
83-
throw new Error(errorMsg); // Fail tests early in CI if teardown fails
71+
console.error('\x1b[31m%s\x1b[0m', `✗ E2E teardown failed: ${res.status}`);
72+
if (attempt < maxAttempts - 1) {
73+
console.log('');
74+
}
75+
} catch (error) {
76+
console.error('\x1b[31m%s\x1b[0m', `✗ E2E teardown error: ${error.message || String(error)}`);
77+
if (attempt < maxAttempts - 1) {
78+
console.log('');
8479
}
85-
}
86-
} else {
87-
// Only warn for local/dev testing, don't fail
88-
if (process.env.E2E_LOCAL === 'true' || process.env.E2E_DEV === 'true') {
89-
console.log('\n', '\x1b[33m', 'e2e teardown skipped (no token) - OK for local testing', '\x1b[0m', '\n');
90-
} else {
91-
const errorMsg = 'e2e teardown failed - no available token (set E2E_TEST_TOKEN or E2E_TEST_TOKEN_<ENV>)';
92-
console.error('\n', '\x1b[31m', errorMsg, '\x1b[0m', '\n');
93-
throw new Error(errorMsg); // Fail tests in CI if token is missing
9480
}
9581
}
9682

97-
console.log('Starting E2E tests');
83+
const errorMsg = `e2e teardown failed after ${maxAttempts} attempts`;
84+
console.error('\n', '\x1b[31m', errorMsg, '\x1b[0m', '\n');
85+
throw new Error(errorMsg);
9886
}
9987

10088
export default globalSetup;

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": "npx -y tsx e2e/run-with-retry.ts",
1313
"test:run": "npm run test:bundle && cross-env NODE_ENV=production E2E=true npx playwright test",
1414
"test:dev": "cross-env NODE_ENV=production E2E=true E2E_DEV=true npx playwright test --ui",
15-
"test:devlocal": "cross-env NODE_ENV=production E2E_LOCAL=true E2E_CONCURRENCY=1 E2E=true E2E_DEV=true npx playwright test --ui",
15+
"test:devlocal": "cross-env NODE_ENV=production E2E=true E2E_DEV=true E2E_LOCAL=true E2E_CONCURRENCY=1 npx playwright test --ui",
1616
"test:devBundle": "npm run test:bundle && npm run test:dev",
1717
"test:install": "npx playwright install firefox",
1818
"test:teardown": "npx tsx e2e/teardown.ts",

0 commit comments

Comments
 (0)