Skip to content

Commit 22cfd2b

Browse files
awaseemcharislam
andauthored
feat: Run E2E tests aganist Platform Pt.1 (supabase#41032)
* added packages for creating projects * updated scripts * remove ami version * cleaned up common * updated tests * refactored helpers * updated env * updated config * updated to reference env * updated global setup * updated type logic and scripts * added mocking of hcaptcha * added log statements * updated local env * update env file * updated env vars * updated logging * updated to remove check * updated print and project names * updated helpers * updated url * updated setup * updated storage helpers to account for listing files * updated setup and tests * updated timeout only for setup * updated helper to account for different api response * added ignores for tests * updated lock file * updated database spec to add exact * updated timeouts * removed check for table grid footer * updated test runner * updated is_platform * updated playwright config * updated worker settings * removed dotenvx * updated README * updated to remove comment * Update e2e/studio/scripts/common/retriedFetch.ts Co-authored-by: Charis <[email protected]> --------- Co-authored-by: Charis <[email protected]>
1 parent b9908ae commit 22cfd2b

29 files changed

+720
-220
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Copy and paste this file and rename it to .env.local
3+
4+
# Required for self hosted tests
5+
# Mise infra running
6+
STUDIO_URL=http://localhost:8082
7+
API_URL=http://localhost:8080
8+
9+
# Required for platform tests
10+
IS_PLATFORM=true
11+
ORG_SLUG=
12+
SUPA_PAT=
13+
EMAIL=
14+
PASSWORD=
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
# Copy and paste this file and rename it to .env.local
33

4+
# Required for self hosted tests
45
STUDIO_URL=http://localhost:8082
56
API_URL=http://127.0.0.1:54321
6-
IS_PLATFORM=false
77

8-
# Used to run e2e tests against vercel previews
9-
VERCEL_AUTOMATION_BYPASS_SELFHOSTED_STUDIO=
8+
# Required for platform tests
9+
IS_PLATFORM=false

e2e/studio/README.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22

33
## Set up
44

5+
### Prerequisites
6+
7+
#### For Self-Hosted Tests
8+
9+
- Nothing is required, running with IS_PLATFORM=false should run the tests locally with a self hosted docker container
10+
11+
#### For Platform Tests
12+
13+
1. **Create a platform account** with an email and password, these auths are used for the test
14+
2. **Create an organization** on the platform, this can be done if run locally through `mise fullstack`
15+
3. **Generate a Personal Access Token (PAT)** for API access
16+
4. Configure the environment variables below
17+
18+
### Configure Environment
19+
520
```bash
621
cp .env.local.example .env.local
722
```
823

24+
Edit `.env.local` and set the appropriate values based on your test environment (see Environment Variables section below).
25+
926
### Install the playwright browser
1027

1128
⚠️ This should be done in the `e2e/studio` directory
@@ -18,9 +35,45 @@ pnpm exec playwright install
1835

1936
### Environment Variables
2037

21-
Some tests require specific environment variables to be set. If these are not set, the tests will be automatically skipped:
38+
Configure your tests by setting the following environment variables in `.env.local`. We have examples of what required on self hosted and platform:
39+
40+
#### Core Configuration
41+
42+
- **`STUDIO_URL`**: The URL where Studio is running (default: `http://localhost:8082`)
43+
- **`API_URL`**: The Supabase API endpoint (default: `https://localhost:8080`)
44+
- **`IS_PLATFORM`**: Set to `true` for platform tests, `false` for self-hosted (default: `false`)
45+
- When `true`: Tests run serially (1 worker) due to API rate limits
46+
- When `false`: Tests run in parallel (5 workers)
47+
48+
#### Authentication (Required for Platform Tests)
49+
50+
⚠️ **Before running platform tests, you must create an account with an email, password, and organization on the platform you're testing.**
51+
52+
- **`EMAIL`**: Your platform account email (required for authentication)
53+
- **`PASSWORD`**: Your platform account password (required for authentication)
54+
- **`PROJECT_REF`**: Project reference (optional, will be auto-created if not provided)
55+
56+
When both `EMAIL` and `PASSWORD` are set, authentication is automatically enabled. HCaptcha is mocked during test setup.
57+
58+
#### Platform-Specific Variables (Required when `IS_PLATFORM=true`)
59+
60+
- **`ORG_SLUG`**: Organization slug (default: `default`)
61+
- **`SUPA_REGION`**: Supabase region (default: `us-east-1`)
62+
- **`SUPA_PAT`**: Personal Access Token for API authentication (default: `test`)
63+
- **`BRANCH_NAME`**: Name for the test branch/project (default: `e2e-test-local`)
64+
65+
#### Optional Variables
2266

2367
- **`OPENAI_API_KEY`**: Required for the AI Assistant test (`assistant.spec.ts`). Without this variable, the assistant test will be skipped.
68+
- **`VERCEL_AUTOMATION_BYPASS_SELFHOSTED_STUDIO`**: Bypass token for Vercel protection (default: `false`)
69+
70+
#### Setup Commands Based on Configuration
71+
72+
The test setup automatically runs different commands based on your environment:
73+
74+
- **Platform + Localhost** (`IS_PLATFORM=true` and `STUDIO_URL=localhost`): Runs `pnpm run e2e:setup:platform`
75+
- **Platform + Remote** (`IS_PLATFORM=true` and remote `STUDIO_URL`): No web server setup
76+
- **Self-hosted** (`IS_PLATFORM=false`): Runs `pnpm run e2e:setup:selfhosted`
2477

2578
---
2679

e2e/studio/env.config.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1+
import dotenv from 'dotenv'
12
import path from 'path'
23

4+
// Load .env.local before reading process.env
5+
dotenv.config({
6+
path: path.resolve(import.meta.dirname, '.env.local'),
7+
override: true,
8+
})
9+
310
const toBoolean = (value?: string) => {
411
if (value == null) return false
512
const normalized = value.trim().toLowerCase()
613
return normalized === 'true'
714
}
815

916
export const env = {
10-
STUDIO_URL: process.env.STUDIO_URL,
11-
API_URL: process.env.API_URL || 'https://api.supabase.green',
12-
AUTHENTICATION: toBoolean(process.env.AUTHENTICATION),
17+
STUDIO_URL: process.env.STUDIO_URL || 'http://localhost:8082',
18+
API_URL: process.env.API_URL || 'https://localhost:8080',
19+
20+
IS_PLATFORM: toBoolean(process.env.IS_PLATFORM || 'false'),
1321
EMAIL: process.env.EMAIL,
1422
PASSWORD: process.env.PASSWORD,
15-
PROJECT_REF: process.env.PROJECT_REF || 'default',
16-
IS_PLATFORM: process.env.IS_PLATFORM || 'false',
23+
PROJECT_REF: process.env.PROJECT_REF || undefined,
24+
1725
VERCEL_AUTOMATION_BYPASS_SELFHOSTED_STUDIO:
1826
process.env.VERCEL_AUTOMATION_BYPASS_SELFHOSTED_STUDIO || 'false',
27+
ORG_SLUG: process.env.ORG_SLUG || 'default',
28+
SUPA_REGION: process.env.SUPA_REGION || 'us-east-1',
29+
SUPA_PAT: process.env.SUPA_PAT || 'test',
30+
31+
BRANCH_NAME: process.env.BRANCH_NAME || `e2e-test-local`,
32+
33+
AUTHENTICATION: Boolean(process.env.EMAIL && process.env.PASSWORD),
34+
35+
IS_APP_RUNNING_ON_LOCALHOST:
36+
process.env.STUDIO_URL?.includes('localhost') || process.env.STUDIO_URL?.includes('127.0.0.1'),
1937
}
2038

2139
export const STORAGE_STATE_PATH = path.join(import.meta.dirname, './playwright/.auth/user.json')

e2e/studio/examples/examples.ts

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)