Skip to content

Commit 53c1df6

Browse files
committed
chore(repo): cleanup and update docs
1 parent d754e7f commit 53c1df6

File tree

8 files changed

+230
-343
lines changed

8 files changed

+230
-343
lines changed

deno.lock

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/TESTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ Each package has unique testing requirements. Please refer to the individual REA
2222

2323
### Core Packages
2424

25-
| Package | Docker Required | Test Command | Documentation |
26-
| ---------------- | ---------------------------------------- | -------------------------------- | ------------------------------------------------------------- |
27-
| **auth-js** | ✅ Yes (GoTrue + PostgreSQL) | `npx nx test:auth auth-js` | [Testing Guide](packages/core/auth-js/README.md#testing) |
28-
| **functions-js** | ✅ Yes (Deno relay via testcontainers) | `npx nx test functions-js` | [Testing Guide](packages/core/functions-js/README.md#testing) |
29-
| **postgrest-js** | ✅ Yes (PostgREST + PostgreSQL) | `npx nx test postgrest-js` | [Testing Guide](packages/core/postgrest-js/README.md#testing) |
30-
| **realtime-js** | ❌ No (uses mock WebSockets) | `npx nx test realtime-js` | [Testing Guide](packages/core/realtime-js/README.md#testing) |
31-
| **storage-js** | ✅ Yes (Storage API + PostgreSQL + Kong) | `npx nx test:storage storage-js` | [Testing Guide](packages/core/storage-js/README.md#testing) |
32-
| **supabase-js** | ❌ No (unit tests only) | `npx nx test supabase-js` | [Testing Guide](packages/core/supabase-js/README.md#testing) |
25+
| Package | Docker Required | Test Command | Documentation |
26+
| ---------------- | ---------------------------------------- | -------------------------------- | ---------------------------------------------------------------- |
27+
| **auth-js** | ✅ Yes (GoTrue + PostgreSQL) | `npx nx test:auth auth-js` | [Testing Guide](../packages/core/auth-js/README.md#testing) |
28+
| **functions-js** | ✅ Yes (Deno relay via testcontainers) | `npx nx test functions-js` | [Testing Guide](../packages/core/functions-js/README.md#testing) |
29+
| **postgrest-js** | ✅ Yes (PostgREST + PostgreSQL) | `npx nx test postgrest-js` | [Testing Guide](../packages/core/postgrest-js/README.md#testing) |
30+
| **realtime-js** | ❌ No (uses mock WebSockets) | `npx nx test realtime-js` | [Testing Guide](../packages/core/realtime-js/README.md#testing) |
31+
| **storage-js** | ✅ Yes (Storage API + PostgreSQL + Kong) | `npx nx test:storage storage-js` | [Testing Guide](../packages/core/storage-js/README.md#testing) |
32+
| **supabase-js** | ✅ Yes | `npx nx test supabase-js` | [Testing Guide](../packages/core/supabase-js/TESTING.md) |
3333

3434
### Common Test Commands
3535

packages/core/supabase-js/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ docs/v2
109109
# Test package-lock files (use local tarball, checksums change with builds)
110110
test/*/package-lock.json
111111
test/integration/*/package-lock.json
112+
test/integration/*/bun.lock
112113

113114
.cursor/
114115

packages/core/supabase-js/README.md

Lines changed: 1 addition & 274 deletions
Original file line numberDiff line numberDiff line change
@@ -146,280 +146,7 @@ npx nx build supabase-js --watch
146146

147147
### Testing
148148

149-
**Important:** The test suite includes tests for multiple runtime environments (Node.js, Deno, Bun, Expo, Next.js). Each environment has its own test runner and specific requirements.
150-
151-
#### Prerequisites for All Integration Tests
152-
153-
1. **Docker** must be installed and running
154-
2. **Supabase CLI** must be installed (`npm install -g supabase` or via package manager)
155-
3. **Local Supabase instance** must be started:
156-
157-
```bash
158-
# Navigate to the supabase-js package directory
159-
cd packages/core/supabase-js
160-
161-
# Start Supabase (downloads and starts all required containers)
162-
npx supabase start
163-
164-
# The output will show:
165-
# - API URL: http://127.0.0.1:54321
166-
# - Database URL: postgresql://postgres:[email protected]:54322/postgres
167-
# - Studio URL: http://127.0.0.1:54323
168-
# - Anon key: [your-anon-key]
169-
# - Service role key: [your-service-role-key] # Important for some tests!
170-
171-
# Return to monorepo root for running tests
172-
cd ../../..
173-
```
174-
175-
#### Test Scripts Overview
176-
177-
| Script | Description | Requirements |
178-
| -------------------------- | ----------------------------------------- | --------------------------------------- |
179-
| `test` | Runs unit tests + type checking | None |
180-
| `test:all` | Unit + integration + browser tests | Supabase running |
181-
| `test:run` | Jest unit tests only | None |
182-
| `test:unit` | Jest unit tests in test/unit directory | None |
183-
| `test:coverage` | Unit tests with coverage report | None |
184-
| `test:integration` | Node.js integration tests | Supabase running + SERVICE_ROLE_KEY |
185-
| `test:integration:browser` | Browser tests using Deno + Puppeteer | Supabase running + Deno installed |
186-
| `test:edge-functions` | Edge Functions tests | Supabase running + Deno installed |
187-
| `test:types` | TypeScript type checking + JSR validation | None |
188-
| `test:bun` | Bun runtime compatibility tests | Supabase running + Bun installed |
189-
| `test:node:playwright` | WebSocket browser tests | Supabase running + Playwright |
190-
| Deno (see section below) | Deno runtime compatibility tests | Supabase running + Deno installed |
191-
| Expo (see section below) | React Native/Expo tests | Supabase running + dependencies updated |
192-
| Next.js (see below) | Next.js SSR tests | Supabase running + dependencies updated |
193-
194-
#### Unit Testing
195-
196-
```bash
197-
# Run all unit tests (Jest)
198-
npx nx test supabase-js
199-
200-
# Run only unit tests in test/unit directory
201-
npx nx test:unit supabase-js
202-
203-
# Run tests in watch mode during development
204-
npx nx test supabase-js --watch
205-
206-
# Run tests with coverage report
207-
npx nx test:coverage supabase-js
208-
```
209-
210-
#### Integration Testing
211-
212-
```bash
213-
# Prerequisites: Start Supabase first (see above)
214-
215-
# Run Node.js integration tests
216-
# IMPORTANT: Requires SUPABASE_SERVICE_ROLE_KEY environment variable
217-
cd packages/core/supabase-js
218-
export SUPABASE_SERVICE_ROLE_KEY="$(npx supabase status --output json | jq -r '.SERVICE_ROLE_KEY')"
219-
cd ../../..
220-
npx nx test:integration supabase-js
221-
222-
# Run browser-based integration tests (requires Deno)
223-
npx nx test:integration:browser supabase-js
224-
```
225-
226-
#### Running All Tests
227-
228-
```bash
229-
# This runs type checking, unit tests, and integration tests sequentially
230-
# NOTE: Will fail if Supabase is not running or dependencies not updated
231-
npx nx test:all supabase-js
232-
```
233-
234-
**Common Issues and Solutions:**
235-
236-
| Issue | Solution |
237-
| -------------------------------------------- | --------------------------------------------------------------- |
238-
| "Cannot find module 'https://deno.land/...'" | Deno tests incorrectly run by Jest - check `jest.config.ts` |
239-
| "Port 54322 already allocated" | Stop existing Supabase: `npx supabase stop --project-id <name>` |
240-
| "503 Service Unavailable" for Edge Functions | Supabase not running - start with `npx supabase start` |
241-
| "Uncommitted changes" during type check | Commit changes or add `--allow-dirty` to JSR publish |
242-
| Integration tests fail with auth errors | Export `SUPABASE_SERVICE_ROLE_KEY` (see Integration Testing) |
243-
244-
### Platform-Specific Testing
245-
246-
#### Expo Testing (React Native)
247-
248-
```bash
249-
# Prerequisites:
250-
# 1. Supabase must be running (see Prerequisites)
251-
# 2. Update test dependencies and pack current build
252-
cd packages/core/supabase-js
253-
npm run update:test-deps:expo
254-
255-
# Run Expo tests from the Expo test project
256-
cd test/integration/expo
257-
npm install
258-
npm test
259-
cd ../../..
260-
```
261-
262-
#### Next.js Testing (SSR)
263-
264-
```bash
265-
# Prerequisites:
266-
# 1. Supabase must be running (see Prerequisites)
267-
# 2. Update test dependencies and pack current build
268-
npx nx update:test-deps:next supabase-js
269-
270-
# 3. Install Playwright browsers and dependencies
271-
npx playwright install --with-deps
272-
273-
# Run Next.js tests from the Next test project
274-
cd packages/core/supabase-js/test/integration/next
275-
npm install --legacy-peer-deps
276-
npm run test
277-
cd ../../..
278-
```
279-
280-
#### Deno Testing
281-
282-
```bash
283-
# Prerequisites:
284-
# 1. Deno must be installed (https://deno.land)
285-
# 2. Supabase must be running (see Prerequisites)
286-
# 3. Update test dependencies:
287-
npx nx update:test-deps:deno supabase-js
288-
289-
# Run Deno tests
290-
npx nx test:deno supabase-js
291-
```
292-
293-
### Edge Functions Testing
294-
295-
The project includes Edge Functions integration tests that require a local Supabase instance to be running.
296-
297-
```bash
298-
# Prerequisites:
299-
# 1. Ensure Docker is installed and running
300-
# 2. Navigate to the supabase-js package directory
301-
cd packages/core/supabase-js
302-
303-
# 3. Start Supabase locally (this will download and start all required containers)
304-
npx supabase start
305-
306-
# Wait for the output showing all services are ready, including:
307-
# - API URL: http://127.0.0.1:54321
308-
# - Database URL: postgresql://postgres:[email protected]:54322/postgres
309-
# - Edge Runtime container
310-
311-
# 4. Run the Edge Functions tests from the monorepo root
312-
cd ../../../ # Back to monorepo root
313-
npx nx test:edge-functions supabase-js
314-
```
315-
316-
**Important Notes:**
317-
318-
- The Edge Functions tests will fail with 503 errors if Supabase is not running
319-
- If you encounter port conflicts (e.g., "port 54322 already allocated"), stop any existing Supabase instances:
320-
321-
```bash
322-
npx supabase stop --project-id <project-name>
323-
# Or stop all Docker containers if unsure:
324-
docker ps | grep supabase # List all Supabase containers
325-
```
326-
327-
- The tests use the default local development credentials (anon key)
328-
- Edge Functions are automatically served when `supabase start` is run
329-
330-
#### Bun Testing
331-
332-
```bash
333-
# Prerequisites:
334-
# 1. Bun must be installed (https://bun.sh)
335-
# 2. Supabase must be running (see Prerequisites)
336-
# 3. Update test dependencies:
337-
npx nx update:test-deps:bun supabase-js
338-
339-
# Run Bun tests
340-
npx nx test:bun supabase-js
341-
```
342-
343-
#### WebSocket Browser Testing
344-
345-
```bash
346-
# Prerequisites:
347-
# 1. Supabase must be running (see Prerequisites)
348-
# 2. Build the UMD bundle first:
349-
npx nx build supabase-js
350-
351-
# Run WebSocket browser tests with Playwright
352-
cd packages/core/supabase-js/test/integration/node-browser
353-
npm install
354-
cp ../../../dist/umd/supabase.js .
355-
npm run test
356-
cd ../../..
357-
```
358-
359-
#### CI/CD Testing
360-
361-
When running on CI, the tests automatically use the latest dependencies from the root project. The CI pipeline:
362-
363-
1. Builds the main project with current dependencies
364-
2. Creates a package archive (`.tgz`) with the latest versions
365-
3. Uses this archive in Expo, Next.js, Deno, and Bun tests to ensure consistency
366-
367-
### Updating Test Dependencies
368-
369-
The platform-specific tests (Expo, Next.js, Deno, Bun) use a packaged version of supabase-js rather than directly importing from source. This ensures they test the actual built package as it would be consumed by users.
370-
371-
#### How It Works
372-
373-
1. **Build** the current supabase-js package
374-
2. **Pack** it into a `.tgz` file (like `npm pack` does)
375-
3. **Copy** the `.tgz` to the test directory
376-
4. **Install** it in the test project
377-
378-
This mimics how real users would install and use the package.
379-
380-
#### Update Scripts
381-
382-
```bash
383-
# Update ALL test environment dependencies at once
384-
# This builds, packs, and installs in all test directories
385-
npx nx update:test-deps supabase-js
386-
387-
# Or update specific test environments:
388-
npx nx update:test-deps:expo supabase-js # Expo/React Native only
389-
npx nx update:test-deps:next supabase-js # Next.js only
390-
npx nx update:test-deps:deno supabase-js # Deno only
391-
npx nx update:test-deps:bun supabase-js # Bun only
392-
```
393-
394-
**When to Update:**
395-
396-
- After making changes to the source code
397-
- Before running platform-specific tests locally
398-
- When debugging test failures that might be due to stale dependencies
399-
400-
**Note:** CI automatically handles this, so manual updates are only needed for local development.
401-
402-
### Test Coverage
403-
404-
#### Viewing Coverage Reports
405-
406-
```bash
407-
# Generate coverage report
408-
npx nx test:coverage supabase-js
409-
410-
# Serve coverage report locally (opens interactive HTML report)
411-
npx nx serve:coverage supabase-js
412-
# This starts a local server at http://localhost:3000 with the coverage report
413-
```
414-
415-
The coverage report shows:
416-
417-
- Line coverage
418-
- Branch coverage
419-
- Function coverage
420-
- Uncovered lines with highlights
421-
422-
Coverage results are also automatically uploaded to Coveralls in CI for tracking over time.
149+
Please read our [testing guide](./TESTING.md) for detailed instructions on how to run your tests locally.
423150

424151
### Contributing
425152

0 commit comments

Comments
 (0)