inMemory

fun Offline.Config.inMemory(clock: Clock = Clock.System)(source)

Keeps the plugin's local data in memory, for tests: the cache, the mutation queue and the Storage file cache live in the client, and nothing is written to disk. Every other setting applies as it does in an app, so a test builds its client exactly as production does:

val supabase = createSupabaseClient(url, key) {
httpEngine = MockEngine { request -> … }
install(Postgrest)
install(Offline) { inMemory(clock = testClock) }
}

Each client starts empty, and a second client over the same configuration shares nothing with the first. A CachedFile.path names a file that exists only in the client's memory: read it through the offline bucket, not from disk. supabase-kt's own plugins keep their own state: in a test, give Storage a MemoryResumableCache and Auth a session manager that keeps the session in memory.

The client watches no connectivity monitor: SyncStatus.network stays NetworkStatus.UNKNOWN, which counts as online, unless the test sets Offline.Config.networkAvailability or calls Offline.disableNetwork. To take the client offline, call disableNetwork(): reads are answered from the cache and writes are queued, as on a device in airplane mode, until enableNetwork(). To see how the app meets a server that fails or a connection that drops, fail the requests in the mock engine instead.

The client runs on real time, not a test's virtual clock. supabase-kt retries a request that fails at the transport, so a read the cache cannot answer waits out its retries (about seven seconds) unless the test installs Postgrest { maxRetries = 0 }. A refresh or a replay that failed waits a few seconds, then up to a minute, before it tries again by itself: a networkAvailability flow turning true wakes the refresh at once, and the replay too with autoSync on, and syncPendingMutations() sends without waiting.

Use it under Robolectric too. The platform's own database needs a SQLite binary for the host, and it records the application context once per process, so a later test's client would open an earlier test's database.

Parameters

clock

the time the client sees: when rows were fetched and writes queued, and so how old a cached read is against a maxAge.