Skip to content

test(auth): use supabase cli for most - docker for rest#2040

Merged
mandarini merged 5 commits into
masterfrom
test/supabase-cli-authjs
Jan 22, 2026
Merged

test(auth): use supabase cli for most - docker for rest#2040
mandarini merged 5 commits into
masterfrom
test/supabase-cli-authjs

Conversation

@mandarini

Copy link
Copy Markdown
Contributor

Summary

This PR migrates the auth-js test infrastructure from a multi-instance Docker Compose setup to a single Supabase CLI instance for the majority of tests, while preserving Docker-based tests for edge cases that require specific GoTrue configurations.

Motivation

The original auth-js test setup used Docker Compose to run 4 separate GoTrue instances with different configurations:

Port Configuration Use Case
9999 Signup enabled, autoconfirm OFF Email verification flows, SMS tests
9998 Signup enabled, autoconfirm ON Standard auth flows
9997 Signup disabled, autoconfirm OFF Signup disabled tests
9996 Signup enabled, asymmetric keys RS256 JWT verification

We have decided to move our test suites to use the supabase CLI wherever possible. It provides a simpler, faster alternative that covers the majority of test scenarios with a single instance.

Changes

New Test Structure

packages/core/auth-js/test/
├── lib/
│   └── clients.ts          # CLI clients only (simplified)
├── docker-tests/
│   ├── clients.ts          # Docker clients (self-contained)
│   ├── signup-disabled.test.ts
│   ├── asymmetric-jwt.test.ts
│   ├── phone-otp.test.ts
│   └── anonymous-disabled.test.ts
├── supabase/
│   └── config.toml         # Supabase CLI configuration
├── GoTrueClient.test.ts    # Main tests (CLI)
├── GoTrueApi.test.ts       # Admin API tests (CLI)
└── ...other test files

Test Distribution

Test Suite Runner Tests Description
test:auth Supabase CLI 331 Standard auth flows
test:docker Docker Compose 11 Edge cases requiring specific configs

Docker-Only Tests (11 total)

These tests require GoTrue configurations not possible with a single CLI instance:

  1. Signup Disabled (1 test)

    • Requires GOTRUE_DISABLE_SIGNUP=true
  2. Asymmetric JWT / RS256 (3 tests)

    • Requires GoTrue configured with RS256 signing keys
    • CLI uses HS256 by default
  3. Phone OTP / SMS (6 tests)

    • Requires Twilio SMS provider configuration
    • CLI does not include SMS provider setup
  4. Anonymous Sign-in Disabled (1 test)

    • Requires GOTRUE_EXTERNAL_ANONYMOUS_USERS_ENABLED=false

Targets/Scripts to run

Target Description
test:auth Full CLI test lifecycle (331 tests)
test:infra Start Supabase CLI instance
test:suite Run CLI tests only
test:docker Full Docker test lifecycle (11 tests)
test:docker:infra Start Docker containers
test:docker:suite Run Docker tests only

### CI Configuration

The CI workflow runs both test suites in parallel:

```yaml
jobs:
  setup-build-test-node-20:
    # Runs test:auth (CLI tests) - 331 tests
    
  test-auth-js-docker:
    # Runs test:docker (Docker tests) - 11 tests

Supabase CLI Configuration

Key settings in test/supabase/config.toml:

[auth]
enable_anonymous_sign_ins = true

[auth.email]
enable_confirmations = false  # Autoconfirm ON

[auth.sms]
enable_signup = true
max_frequency = "1s"

[auth.sms.test_otp]
"1234567890" = "123456"

[auth.mfa.totp]
enroll_enabled = true
verify_enabled = true

[auth.mfa.phone]
enroll_enabled = true
verify_enabled = true

How to Test

Run CLI tests locally

npx nx test:auth auth-js

Run Docker tests locally

npx nx test:docker auth-js

Bug Fixes

This PR also fixes a pre-existing test bug:

  • fetchJwk tests leaking mocked fetch - The fetchJwk tests were overriding authWithSession['fetch'] with a mock but never restoring it. This caused subsequent tests (like signInAnonymously) to fail because they used the mocked fetch that returned JWKS data instead of auth responses. Fixed by adding beforeEach/afterEach to save and restore the original fetch.

@mandarini mandarini requested review from a team as code owners January 21, 2026 08:44
@github-actions github-actions Bot added the auth-js Related to the auth-js library. label Jan 21, 2026
@mandarini mandarini self-assigned this Jan 21, 2026
@mandarini mandarini force-pushed the test/supabase-cli-authjs branch from e1c2833 to 51dcf67 Compare January 21, 2026 09:11
Comment thread packages/core/auth-js/test/supabase/signing_keys.json Outdated
Comment thread packages/core/auth-js/test/lib/clients.ts Outdated
@mandarini mandarini force-pushed the test/supabase-cli-authjs branch from 21e75f3 to 929429e Compare January 21, 2026 11:48
@mandarini mandarini requested a review from staaldraad January 21, 2026 13:12
@mandarini mandarini force-pushed the test/supabase-cli-authjs branch from fdb9a70 to 98d7b67 Compare January 22, 2026 12:20
@mandarini mandarini merged commit 6f2d958 into master Jan 22, 2026
29 checks passed
@mandarini mandarini deleted the test/supabase-cli-authjs branch January 22, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auth-js Related to the auth-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants