initializeTestSupabase function
Future<Supabase>
initializeTestSupabase({
- Client? httpClient,
- String url = 'http://localhost:54321',
- String? publishableKey,
- Map<
String, String> ? headers, - WebSocketTransport? realtimeTransport,
- AuthAsyncStorage? asyncStorage,
- bool autoRefreshToken = false,
Initializes Supabase for a test and returns the instance.
Compared to Supabase.initialize, this keeps the session and the pkce
code verifier in memory through asyncStorage, which defaults to a fresh
MemoryAuthAsyncStorage, turns off the token auto refresh so no timer
outlives the test, disables deep link detection so no platform channel is
touched, and defaults publishableKey to testPublishableKey. Pass a
MockSupabaseHttpClient as httpClient to answer the requests, and the
call method of a MockRealtimeTransport as realtimeTransport to
answer the realtime traffic.
Dispose the instance when the test ends, for example with
addTearDown(supabase.dispose), so the next test can initialize again.
Implementation
@visibleForTesting
Future<Supabase> initializeTestSupabase({
Client? httpClient,
String url = 'http://localhost:54321',
String? publishableKey,
Map<String, String>? headers,
WebSocketTransport? realtimeTransport,
AuthAsyncStorage? asyncStorage,
bool autoRefreshToken = false,
}) {
return Supabase.initialize(
url: url,
publishableKey: publishableKey ?? testPublishableKey,
httpClient: httpClient,
headers: headers,
realtimeClientOptions: RealtimeClientOptions(transport: realtimeTransport),
authOptions: FlutterAuthClientOptions(
autoRefreshToken: autoRefreshToken,
asyncStorage: asyncStorage ?? MemoryAuthAsyncStorage(),
detectSessionInUri: false,
),
);
}