Repository navigation
refactor: share the test helpers through supabase_common - #1745
Conversation
Extends the supabase_common testing library with the fixtures and mock HTTP client primitives the package suites kept re-implementing: the session fixture, the fixed test user and token endpoint response, JWT builders (signed and unsigned), a JSON response mock client, the 420 failing client, an abort-aware stalling helper, and the realtime postgres_changes frame builder with the todos column fixture. The suites of supabase_auth, supabase, supabase_flutter, supabase_realtime, supabase_storage, supabase_functions, postgrest, and iceberg now build on those shared helpers, and supabase_flutter's MockAsyncStorage reuses MemoryAuthAsyncStorage instead of reimplementing it, which also drops the dart_jsonwebtoken dev dependency from supabase_flutter.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (27)
💤 Files with no reviewable changes (6)
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe change centralizes HTTP, Realtime, session, and JWT test helpers in ChangesShared testing infrastructure
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to This change consolidates duplicated test helpers without changing production behavior, and the reported analysis, test, and compliance checks pass. No actionable merge-blocking risk remains beyond normal review. Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Follow-up to #1745, which consolidated the test helpers of all the client suites into `supabase_common`'s testing library. This PR breaks those helpers out into a new published `supabase_testing` package aimed at consumers, keeps `supabase_common` a purely internal package, and adds the helpers and documentation that make testing an app against Supabase easy. ## The package split - `packages/supabase_testing` is a new published package holding the customer-facing helpers: the mock HTTP clients, JWT builders, auth fixtures and realtime frame builders from #1745. All nine client package suites now consume them from there as a dev dependency. - `supabase_common` goes back to its internal branding (README, pubspec description and topics). Its `testing.dart` shrinks back to the repo-internal local stack configuration, which is tied to this repository's `supabase/config.toml` and is not useful to consumers. - `supabase_testing` is excluded from the capability-matrix scan, since test helpers are not SDK client surface. ## New helpers Built on top of the moved primitives, verified by their own test suite: - **`MockSupabaseHttpClient`**: answers requests from stubs registered per endpoint, with shorthands for the service layouts so tests never spell out URL paths: `stubTable` (`/rest/v1/<table>`), `stubRpc`, `stubEdgeFunction` and `stubSignIn` (a working token endpoint). The latest matching stub wins, `times` limits how often a stub answers so call sequences can be modeled, and an unmatched request throws a `StateError` naming the request and the registered stubs. Every answered request is recorded with its body already read (`request.jsonBody`), so tests can assert on what the code under test sent. - **`testSupabaseClient`**: a `SupabaseClient` wired for tests, removing the footguns of constructing one by hand: in-memory pkce storage, token auto refresh off so no timer outlives the test, and an unsigned anon JWT as the default API key. - **`signInTestUser`**: puts a client into a signed-in state without any network traffic (through `recoverSession` with generated fixtures), so any test can run as an authenticated user with custom id, email, role and claims. - **`decodeTestJwtClaims`**: reads claims back out of a token for assertions. ## Documentation - The `supabase_testing` README is a full testing guide: quickstart, stubbing each service, error and sequence stubbing, asserting on recorded requests, running tests as a signed-in user, testing sign-in flows, realtime frames, wiring `Supabase.initialize` in Flutter widget tests, and when to reach for a real local stack instead. - The root README gains a "Testing your app" section pointing at the package. Every code sample in the READMEs was executed as a real test before being inlined, including the Flutter `Supabase.initialize` recipe. ## Testing - New `supabase_testing` suite covers the mock client (matching precedence, `times`, unmatched error, request recording, all shorthands), the client factory and `signInTestUser`. - Full suites of all ten touched packages pass against the local CLI stack (1573 tests). - `dart analyze` clean across the workspace, `dart format` reports no changes, compliance symbol scan unaffected. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added the `supabase_testing` package with tools for mocking Supabase requests, stubbing tables, RPCs, and Edge Functions, recording requests, and testing authentication and realtime integrations. * Added local test-client helpers, session fixtures, JWT utilities, and reusable HTTP mocks. * **Documentation** * Added comprehensive setup and usage guidance for application testing. * **Chores** * Updated package testing configurations to use the new testing toolkit. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Follow-up to #1572 (SDK-1281): a duplication sweep after the extraction tiers landed showed that the remaining copy-paste lives almost entirely in the test suites. This PR grows
supabase_common's existingtesting.dartlibrary with the helpers the suites kept re-implementing and moves the tests onto them.New shared helpers
getSessionData,sessionDataUserId): was copied byte-for-byte in thesupabase,supabase_flutter, andsupabase_authtest utils.testUserJson,testSessionResponseJson,testUserId): the roughly 60-line signed-session response was duplicated verbatim betweensupabase_auth'sRetryTestHttpClientandsupabase_flutter'sPkceHttpClient, down to the same signing key.signedTestJwt,unsignedTestJwt): replace five hand-rolled builders across the auth, flutter, and realtime suites. The auth and flutter mock clients now sign with the shared HS256 helper instead ofdart_jsonwebtoken, which letssupabase_flutterdrop that dev dependency.jsonStreamedResponse,JsonResponseMockClient,FailingHttpClient,stallUntilAborted): the JSON response builder existed in iceberg and auth, the 420 failing client in storage and auth, and the abort-trigger stalling block identically in the postgrest and supabase suites.postgresChangesFrame,todoColumns): thetodoscolumn fixture appeared eight times across the two mock WebSocket servers insupabase_realtimeandsupabase.Cleanups along the way
supabase_flutter'sMockAsyncStoragewas a verbatim reimplementation ofMemoryAuthAsyncStorage; it now extends it.supabase_auth's single-purposeCustomHttpClient(420) is replaced by the sharedFailingHttpClient.No production code changes outside the
supabase_commontesting library, which is excluded from the capability-matrix scan.Testing
dart analyzeclean across all touched packagesSummary by CodeRabbit
Refactor
Tests
Chores