Skip to content

Commit c68e3f9

Browse files
committed
test(auth): split test infra for docker and cli
1 parent 6d35797 commit c68e3f9

File tree

18 files changed

+1002
-401
lines changed

18 files changed

+1002
-401
lines changed

.github/workflows/ci-core.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,26 @@ jobs:
6161
flag-name: realtime-js
6262
fail-on-error: false
6363
continue-on-error: true
64-
- name: Run auth-js tests (if affected)
64+
65+
- name: Setup Supabase CLI (for auth-js and storage-js tests)
66+
uses: supabase/setup-cli@v1
67+
with:
68+
version: latest
69+
70+
- name: Run auth-js tests with Supabase CLI (if affected)
6571
run: npx nx affected --target=test:auth
72+
timeout-minutes: 10
6673

6774
- name: Upload coverage for auth-js (if affected)
6875
uses: coverallsapp/github-action@v2
6976
with:
7077
github-token: ${{ secrets.GITHUB_TOKEN }}
71-
path-to-lcov: ./packages/core/auth-js/test/coverage/lcov.info
78+
path-to-lcov: ./packages/core/auth-js/coverage/lcov.info
7279
parallel: true
7380
flag-name: auth-js
7481
fail-on-error: false
7582
continue-on-error: true
7683

77-
- name: Setup Supabase CLI (for storage-js tests)
78-
uses: supabase/setup-cli@v1
79-
with:
80-
version: latest
81-
8284
- name: Run storage-js tests (if affected)
8385
run: npx nx affected --target=test:storage
8486

@@ -91,6 +93,28 @@ jobs:
9193
flag-name: storage-js
9294
fail-on-error: false
9395
continue-on-error: true
96+
97+
# Separate job for auth-js Docker tests (full coverage including edge cases)
98+
test-auth-js-docker:
99+
name: Test auth-js (Docker - Full Coverage)
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@v4
103+
with:
104+
filter: tree:0
105+
fetch-depth: 0
106+
- uses: actions/setup-node@v4
107+
with:
108+
node-version: 20
109+
cache: 'npm'
110+
- name: Install dependencies
111+
run: npm ci
112+
- uses: nrwl/nx-set-shas@v4
113+
114+
- name: Run auth-js Docker tests (if affected)
115+
run: npx nx affected --target=test:docker --projects=@supabase/auth-js
116+
timeout-minutes: 10
117+
94118
# Separate job for postgrest-js tests (Docker-based, retriable)
95119
test-postgrest-js:
96120
name: Test postgrest-js
@@ -200,6 +224,7 @@ jobs:
200224
needs:
201225
[
202226
setup-build-test-node-20,
227+
test-auth-js-docker,
203228
test-postgrest-js,
204229
check-postgrest-generated-types,
205230
test-postgrest-js-v12,

nx.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
"cache": true,
123123
"outputs": ["{projectRoot}/coverage"]
124124
},
125+
"test:auth": {
126+
"inputs": ["testing", "^production"],
127+
"cache": true,
128+
"outputs": ["{projectRoot}/coverage"]
129+
},
125130
"test:storage": {
126131
"cache": false
127132
},
@@ -139,6 +144,25 @@
139144
"test:clean-post": {
140145
"cache": false
141146
},
147+
"test:docker": {
148+
"inputs": ["testing", "^production"],
149+
"cache": false,
150+
"outputs": []
151+
},
152+
"test:docker:clean-pre": {
153+
"cache": false
154+
},
155+
"test:docker:infra": {
156+
"cache": false
157+
},
158+
"test:docker:suite": {
159+
"inputs": ["testing", "^production"],
160+
"cache": false,
161+
"outputs": []
162+
},
163+
"test:docker:clean-post": {
164+
"cache": false
165+
},
142166
"vite:test": {
143167
"inputs": ["testing", "^production"],
144168
"cache": true,

packages/core/auth-js/README.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -104,60 +104,84 @@ npx nx docs auth-js # Generate documentation
104104

105105
### Testing
106106

107-
**Docker Required!** The auth-js tests require a local Supabase Auth server (GoTrue) running in Docker.
107+
The auth-js package has two test suites:
108+
109+
1. **CLI Tests** - Main test suite using Supabase CLI (331 tests)
110+
2. **Docker Tests** - Edge case tests requiring specific GoTrue configurations (11 tests)
111+
112+
#### Prerequisites
113+
114+
- **Supabase CLI** - Required for main test suite ([installation guide](https://supabase.com/docs/guides/cli))
115+
- **Docker** - Required for edge case tests
116+
117+
#### Running Tests
108118

109119
```bash
110-
# Run complete test suite (from monorepo root)
120+
# Run main test suite with Supabase CLI (recommended)
111121
npx nx test:auth auth-js
122+
123+
# Run Docker-only edge case tests
124+
npx nx test:docker auth-js
125+
126+
# Run both test suites
127+
npx nx test:auth auth-js && npx nx test:docker auth-js
112128
```
113129

114-
This command automatically:
130+
#### Main Test Suite (Supabase CLI)
115131

116-
1. Stops any existing test containers
117-
2. Starts a Supabase Auth server (GoTrue) and PostgreSQL database in Docker
118-
3. Waits for services to be ready (30 seconds)
119-
4. Runs the test suite
120-
5. Cleans up Docker containers after tests complete
132+
The `test:auth` command automatically:
121133

122-
#### Individual Test Commands
134+
1. Stops any existing Supabase instance
135+
2. Starts a local Supabase instance via CLI
136+
3. Runs the test suite (excludes `docker-tests/` folder)
137+
4. Cleans up after tests complete
123138

124139
```bash
125-
# Run just the test suite (requires infrastructure to be running)
126-
npx nx test:suite auth-js
140+
# Individual commands for manual control
141+
npx nx test:infra auth-js # Start Supabase CLI
142+
npx nx test:suite auth-js # Run tests only
143+
npx nx test:clean-post auth-js # Stop Supabase CLI
144+
```
127145

128-
# Manually manage test infrastructure
129-
npx nx test:infra auth-js # Start Docker containers
130-
npx nx test:clean auth-js # Stop and remove containers
146+
#### Docker Tests (Edge Cases)
147+
148+
The `test:docker` target runs tests that require specific GoTrue configurations not possible with a single Supabase CLI instance:
149+
150+
- **Signup disabled** - Tests for disabled signup functionality
151+
- **Asymmetric JWT (RS256)** - Tests for RS256 JWT verification
152+
- **Phone OTP / SMS** - Tests requiring Twilio SMS provider
153+
- **Anonymous sign-in disabled** - Tests for disabled anonymous auth
154+
155+
These tests are located in `test/docker-tests/` and use the Docker Compose setup in `infra/docker-compose.yml`.
156+
157+
```bash
158+
# Individual commands for manual control
159+
npx nx test:docker:infra auth-js # Start Docker containers
160+
npx nx test:docker:suite auth-js # Run Docker tests only
161+
npx nx test:docker:clean-post auth-js # Stop Docker containers
131162
```
132163

133164
#### Development Testing
134165

135166
For actively developing and debugging tests:
136167

137168
```bash
138-
# Start infrastructure once
169+
# Start Supabase CLI once
139170
npx nx test:infra auth-js
140171

141-
# Run tests multiple times (faster since containers stay up)
172+
# Run tests multiple times (faster since instance stays up)
142173
npx nx test:suite auth-js
143174

144175
# Clean up when done
145-
npx nx test:clean auth-js
176+
npx nx test:clean-post auth-js
146177
```
147178

148179
#### Test Infrastructure
149180

150-
The Docker setup includes:
151-
152-
- **Supabase Auth (GoTrue)** - The authentication server
153-
- **PostgreSQL** - Database for auth data
154-
- Pre-configured with test users and settings
155-
156-
#### Prerequisites
157-
158-
- **Docker** must be installed and running
159-
- Ports used by test infrastructure (check `infra/docker-compose.yml`)
160-
- No full Supabase instance needed - just the Auth server
181+
| Suite | Infrastructure | Configuration |
182+
| ------------ | -------------- | --------------------------- |
183+
| CLI Tests | Supabase CLI | `test/supabase/config.toml` |
184+
| Docker Tests | Docker Compose | `infra/docker-compose.yml` |
161185

162186
### Contributing
163187

packages/core/auth-js/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
'^.+\\.tsx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.test.json' }],
88
},
99
collectCoverage: true,
10-
coverageDirectory: 'test/coverage',
10+
coverageDirectory: './coverage',
1111
coverageReporters: ['json', 'html', 'lcov'],
1212
collectCoverageFrom: [
1313
'src/**/*.{js,ts}',

packages/core/auth-js/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
"build": "npm run build:main && npm run build:module",
3030
"build:main": "tsc -p tsconfig.json",
3131
"build:module": "tsc -p tsconfig.module.json",
32-
"test:auth": "npm run test:clean && npm run test:infra && npm run test:suite && npm run test:clean",
33-
"test:suite": "jest --runInBand --coverage",
34-
"test:infra": "cd infra && docker compose down && docker compose pull && docker compose up -d && sleep 30",
35-
"test:clean": "cd infra && docker compose down",
3632
"docs": "typedoc src/index.ts --out docs/v2 --excludePrivate --excludeProtected",
3733
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals --excludePrivate --excludeProtected src/index.ts"
3834
},

packages/core/auth-js/project.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"name": "@supabase/auth-js",
3+
"targets": {
4+
"test:clean-pre": {
5+
"executor": "nx:run-commands",
6+
"options": {
7+
"command": "supabase stop --no-backup || true",
8+
"cwd": "{projectRoot}/test/supabase"
9+
}
10+
},
11+
"test:infra": {
12+
"executor": "nx:run-commands",
13+
"options": {
14+
"command": "supabase start",
15+
"cwd": "{projectRoot}/test/supabase"
16+
},
17+
"dependsOn": ["test:clean-pre"]
18+
},
19+
"test:suite": {
20+
"executor": "nx:run-commands",
21+
"options": {
22+
"command": "jest --runInBand --coverage --testPathIgnorePatterns=docker-tests",
23+
"cwd": "{projectRoot}"
24+
},
25+
"outputs": ["{projectRoot}/coverage"],
26+
"dependsOn": ["test:infra"]
27+
},
28+
"test:clean-post": {
29+
"executor": "nx:run-commands",
30+
"options": {
31+
"command": "supabase stop --no-backup || true",
32+
"cwd": "{projectRoot}/test/supabase"
33+
},
34+
"dependsOn": ["test:suite"]
35+
},
36+
"test:auth": {
37+
"executor": "nx:run-commands",
38+
"options": {
39+
"command": "echo 'Auth-js CLI tests complete'",
40+
"cwd": "{projectRoot}"
41+
},
42+
"dependsOn": ["test:clean-post"],
43+
"metadata": {
44+
"description": "Run auth-js tests with Supabase CLI (excludes docker-tests folder)"
45+
}
46+
},
47+
"test:docker:clean-pre": {
48+
"executor": "nx:run-commands",
49+
"options": {
50+
"command": "docker compose -f infra/docker-compose.yml down || true",
51+
"cwd": "{projectRoot}"
52+
}
53+
},
54+
"test:docker:infra": {
55+
"executor": "nx:run-commands",
56+
"options": {
57+
"commands": [
58+
"docker compose -f infra/docker-compose.yml pull",
59+
"docker compose -f infra/docker-compose.yml up -d",
60+
"sleep 30"
61+
],
62+
"cwd": "{projectRoot}",
63+
"parallel": false
64+
},
65+
"dependsOn": ["test:docker:clean-pre"]
66+
},
67+
"test:docker:suite": {
68+
"executor": "nx:run-commands",
69+
"options": {
70+
"command": "jest --runInBand --testPathPattern=docker-tests",
71+
"cwd": "{projectRoot}"
72+
},
73+
"dependsOn": ["test:docker:infra"]
74+
},
75+
"test:docker:clean-post": {
76+
"executor": "nx:run-commands",
77+
"options": {
78+
"command": "docker compose -f infra/docker-compose.yml down",
79+
"cwd": "{projectRoot}"
80+
},
81+
"dependsOn": ["test:docker:suite"]
82+
},
83+
"test:docker": {
84+
"executor": "nx:run-commands",
85+
"options": {
86+
"command": "echo 'Auth-js Docker tests complete'",
87+
"cwd": "{projectRoot}"
88+
},
89+
"dependsOn": ["test:docker:clean-post"],
90+
"metadata": {
91+
"description": "Run Docker-only tests (signup-disabled, asymmetric-jwt, phone-otp, anonymous-disabled)"
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)