Skip to content

test: run the package suites on the supabase_test helpers - #1827

Merged
spydon merged 4 commits into
mainfrom
test/use-supabase-test-helpers
Sep 10, 2026
Merged

test: run the package suites on the supabase_test helpers#1827
spydon merged 4 commits into
mainfrom
test/use-supabase-test-helpers

Conversation

@spydon

@spydon spydon commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1825. Review that one first; this PR targets its branch.

supabase_test tells app authors to test against a real client with a stubbed HTTP layer, while the package suites of this repo still hand-rolled a BaseClient per test file. This moves them onto the same helpers, which is both a smaller diff to maintain and a continuous check that the published helpers actually cover real testing needs. Net -604 lines.

What changed

28 hand-rolled mock clients removed, replaced by MockSupabaseHttpClient:

Package Files
postgrest filter_escape_test, maybe_single_test, stack_trace_test, typed_query_test
supabase api_key_test, trace_propagation_test, postgrest_options_test
supabase_auth admin_delete_user_test, admin_list_users_test, auto_refresh_dispose_test, client_test, custom_http_client, fetch_test, get_session_test, header_isolation_test, mfa_challenge_mock_test, mfa_enroll_test, refresh_retry_test, refresh_token_race_test, src/set_session_test, sso_mock_test
supabase_storage basic_test, client_test, fetch_test, path_encoding_test, path_normalization_test, vector_test
supabase_flutter widget_test_stubs, deep_link_test, initialization_test
supabase_typegen generated_schema_behavior_test

Two shared helper files are deleted outright: supabase_storage/test/custom_http_client.dart and supabase_auth/test/mocks/sso_mock_client.dart. supabase_auth/test/custom_http_client.dart loses MockedHttpClient and RawBodyHttpClient.

Assertions move from per-mock lastRequest, lastRequestBody, receivedRequests and requestCount fields onto requests, requestsTo and RecordedRequest, so jsonDecode((request as Request).body) becomes request.jsonBody.

Fixtures replace inline copies: signedTestJwt replaces dart_jsonwebtoken in the three tests that minted access tokens, and testUserJson, testSessionResponseJson and getSessionData replace hand-written user and session payloads.

Behaviour worth a second look

  • auto_refresh_dispose_test used a client that called fail() on any request. It now uses a stubless mock, which throws on an unexpected request, plus an explicit expect(httpClient.requests, isEmpty) in tearDown.
  • header_isolation_test uses stubUser, and its admin case stubs /admin/users/<id> explicitly, since the admin API reads a user through its own endpoint.
  • supabase_typegen gains supabase_test as a dev dependency and drops http.

Test plan

Per package, against the local stack: supabase_test 88, supabase 170, postgrest 346, supabase_auth 549, supabase_storage 272, supabase_typegen 64, supabase_flutter 85. All pass except client_test.dart: Signed upload URL cannot upload to a signed url twice in supabase_storage, which fails on main too on a local CLI newer than the pinned 2.109.1 (KeyAlreadyExists instead of Duplicate).

dart analyze and dart format clean across all packages.

Summary by CodeRabbit

  • Tests

    • Standardized HTTP request simulation and response handling across authentication, database, storage, Flutter, and type-generation test suites.
    • Improved coverage and consistency for request headers, query parameters, JSON payloads, retries, errors, and authentication flows.
    • Preserved existing test behavior while simplifying test setup and request inspection.
  • Chores

    • Removed obsolete test-only HTTP helpers and unused testing dependencies.

… bodies

Adds the pieces a test needed a hand-rolled `BaseClient` for:

- `stubError` throws instead of answering, so offline and retry handling
  can be exercised, and `times` limits it to the first requests.
- `stubStall` never answers, so only a timeout or an abort ends the
  request.
- `stubStatuses` answers a sequence of statuses, one per request, and
  repeats the last one once they run out.
- `stubText` answers with a body that is not JSON, under its own content
  type and reason phrase.
- `RecordedRequest.request` holds the request the client received, so a
  multipart upload can be asserted on through its `files`.
- The auth shorthands now answer their endpoint at the root as well, where
  a bare `AuthClient` addresses it, not just under the `/auth/v1` prefix.
- `getSessionData` takes the user the session belongs to.

Also moves the typed api test off `TableColumn`, which was removed in
#1796, so the package suite runs again.
Replaces the hand-rolled `BaseClient` subclasses of the package suites with
`MockSupabaseHttpClient` and the fixtures of `supabase_test`, which is what
the package tells app authors to use.

- 28 mock clients across postgrest, supabase, supabase_auth,
  supabase_storage, supabase_flutter and supabase_typegen are gone, along
  with `supabase_storage/test/custom_http_client.dart` and
  `supabase_auth/test/mocks/sso_mock_client.dart`.
- Request assertions run on `requests`, `requestsTo` and `RecordedRequest`
  instead of per-mock `lastRequest` and `receivedRequests` fields.
- `signedTestJwt` replaces `dart_jsonwebtoken` in the three tests that
  minted their own access tokens, and `testUserJson`,
  `testSessionResponseJson` and `getSessionData` replace the inline copies
  of those payloads.
- supabase_typegen gains supabase_test as a dev dependency and drops http.
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 9e366493-aa0d-4a6e-b623-8cc7156a20e1

📥 Commits

Reviewing files that changed from the base of the PR and between e16317a and cba57ef.

📒 Files selected for processing (36)
  • packages/postgrest/test/filter_escape_test.dart
  • packages/postgrest/test/maybe_single_test.dart
  • packages/postgrest/test/stack_trace_test.dart
  • packages/postgrest/test/typed_query_test.dart
  • packages/supabase/test/api_key_test.dart
  • packages/supabase/test/postgrest_options_test.dart
  • packages/supabase/test/trace_propagation_test.dart
  • packages/supabase_auth/test/admin_delete_user_test.dart
  • packages/supabase_auth/test/admin_list_users_test.dart
  • packages/supabase_auth/test/auto_refresh_dispose_test.dart
  • packages/supabase_auth/test/client_test.dart
  • packages/supabase_auth/test/custom_http_client.dart
  • packages/supabase_auth/test/fetch_test.dart
  • packages/supabase_auth/test/get_session_test.dart
  • packages/supabase_auth/test/header_isolation_test.dart
  • packages/supabase_auth/test/mfa_challenge_mock_test.dart
  • packages/supabase_auth/test/mfa_enroll_test.dart
  • packages/supabase_auth/test/mocks/mfa_recovery_codes_mock_client.dart
  • packages/supabase_auth/test/mocks/sso_mock_client.dart
  • packages/supabase_auth/test/refresh_retry_test.dart
  • packages/supabase_auth/test/refresh_token_race_test.dart
  • packages/supabase_auth/test/src/auth_mfa_api_test.dart
  • packages/supabase_auth/test/src/set_session_test.dart
  • packages/supabase_auth/test/sso_mock_test.dart
  • packages/supabase_flutter/test/deep_link_test.dart
  • packages/supabase_flutter/test/initialization_test.dart
  • packages/supabase_flutter/test/widget_test_stubs.dart
  • packages/supabase_storage/test/basic_test.dart
  • packages/supabase_storage/test/client_test.dart
  • packages/supabase_storage/test/custom_http_client.dart
  • packages/supabase_storage/test/fetch_test.dart
  • packages/supabase_storage/test/path_encoding_test.dart
  • packages/supabase_storage/test/path_normalization_test.dart
  • packages/supabase_storage/test/vector_test.dart
  • packages/supabase_typegen/pubspec.yaml
  • packages/supabase_typegen/test/generated_schema_behavior_test.dart
💤 Files with no reviewable changes (3)
  • packages/supabase_storage/test/custom_http_client.dart
  • packages/supabase_auth/test/custom_http_client.dart
  • packages/supabase_auth/test/mocks/sso_mock_client.dart

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The test suites replace custom HTTP clients with MockSupabaseHttpClient. Tests now use shared stubs and recorded request access across PostgREST, Supabase, Auth, Flutter, Storage, and type generation packages.

Changes

PostgREST tests

Layer / File(s) Summary
Shared mock setup and request assertions
packages/postgrest/test/*
PostgREST tests use shared response stubs and inspect URLs, headers, bodies, and query parameters through recorded requests.

Supabase tests

Layer / File(s) Summary
Client, retry, and trace test migration
packages/supabase/test/*
Supabase tests replace custom HTTP clients with MockSupabaseHttpClient and retain request, retry, header, and trace assertions.

Authentication tests

Layer / File(s) Summary
Authentication HTTP test migration
packages/supabase_auth/test/*
Authentication tests use shared response stubs, request accessors, JWT helpers, and request-count assertions. Obsolete mock client classes are removed.

Flutter integration tests

Layer / File(s) Summary
Deep-link and initialization test migration
packages/supabase_flutter/test/*
Flutter tests use shared mock-client factories for PKCE and user requests. Assertions inspect recorded requests and JSON bodies.

Storage tests

Layer / File(s) Summary
Storage response and request migration
packages/supabase_storage/test/*
Storage tests use stub, stubText, stubError, and recorded request access. Local HTTP test utilities are removed.

Type generation tests

Layer / File(s) Summary
Generated schema test migration
packages/supabase_typegen/pubspec.yaml, packages/supabase_typegen/test/*
Type generation tests use MockSupabaseHttpClient, and supabase_test replaces the direct HTTP development dependency.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: grdsdev

Merge Risk: ⚪ Minimal · up to cba57

The test-mock migration is mergeable with no active production or test-contract risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: updating package test suites to use the shared supabase_test helpers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/use-supabase-test-helpers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

spydon added a commit that referenced this pull request Sep 10, 2026
… bodies (#1825)

Adds the stubbing pieces that the package suites of this repo still
hand-roll a `BaseClient` for. Each one comes from a test that could not
be expressed with the current surface.

## What is new

| Helper | Replaces |
|---|---|
| `stubError(error, {times})` | clients that `throw
ClientException('Offline')` for the first N requests |
| `stubStall()` | clients that never answer, so a timeout or an abort
ends the request |
| `stubStatuses([503, 503, 200])` | clients that walk a retry through a
sequence of statuses |
| `stubText(body, {statusCode, contentType, reasonPhrase})` | clients
returning a non-JSON body, an HTML gateway error for example |
| `RecordedRequest.request` | assertions on what does not survive the
wire format, such as `MultipartRequest.files` |

Two smaller changes in the same vein:

- The auth shorthands (`stubSignIn`, `stubSignUp`, `stubSignOut`,
`stubUser`) now answer their endpoint at the root too, where a bare
`AuthClient` addresses it, and not only under the `/auth/v1` prefix a
`SupabaseClient` uses. The bare path is matched exactly, so a table
named `user` is not caught by `stubUser`.
- `getSessionData` in the internal library takes the user the session
belongs to, instead of being pinned to one id.

## Also in here

`test/typed_api_test.dart` still used `TableColumn`, which #1796
removed, so `dart analyze` and `dart test` were failing on `main` for
this package. It now uses `PostgrestColumn`, which is what the rest of
the repo moved to.

## Notes

- Everything is additive except the auth shorthand matching, which
widens what those four stubs answer.
- `supabase_test` is in `.sdk-parse-ignore`, so none of the new symbols
need registering in `sdk-compliance.yaml`.
- #1827, stacked on this one, moves the package suites onto these
helpers and deletes the hand-rolled clients.

## Test plan

- `dart test` in `packages/supabase_test`: 88 pass, with new groups
covering each helper.
- `dart test` in `packages/supabase_auth` (549) and `packages/supabase`
(170) pass, covering the `getSessionData` and shorthand matching
changes.
- `dart analyze` and `dart format` clean.
Base automatically changed from feat/supabase-test-stub-helpers to main September 10, 2026 13:16
@spydon
spydon merged commit c056717 into main Sep 10, 2026
44 checks passed
@spydon
spydon deleted the test/use-supabase-test-helpers branch September 10, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants