Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/supabase_flutter/lib/src/supabase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:supabase_flutter/src/supabase_auth.dart';

import 'hot_restart_cleanup_stub.dart'
if (dart.library.js_interop) 'hot_restart_cleanup_web.dart';
import 'platform_stub.dart' if (dart.library.io) 'platform_io.dart';
import 'version.dart';

final _log = Logger('supabase.supabase_flutter');
Expand Down Expand Up @@ -103,7 +104,7 @@ class Supabase {
return _instance;
}

_instance._debugEnable = debug ?? kDebugMode;
_instance._debugEnable = debug ?? (kDebugMode && !isRunningInFlutterTest);

if (_instance._debugEnable) {
_instance._logSubscription = Logger('supabase').onRecord.listen((record) {
Expand Down
63 changes: 63 additions & 0 deletions packages/supabase_flutter/test/debug_default_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

import 'widget_test_stubs.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

final logs = <String>[];

setUp(() {
logs.clear();
mockAppLink();
debugPrint = (String? message, {int? wrapWidth}) {
if (message != null) logs.add(message);
};
});

tearDown(() async {
try {
await Supabase.instance.dispose();
} catch (_) {
// Ignore dispose errors
}
});

test(
'debug defaults to off when running under flutter test',
() async {
await Supabase.initialize(
url: '',
publishableKey: '',
authOptions: FlutterAuthClientOptions(
localStorage: const MockLocalStorage(),
pkceAsyncStorage: MockAsyncStorage(),
),
);

expect(
logs.any((log) => log.contains('Supabase init completed')),
isFalse,
);
},
// The default relies on the FLUTTER_TEST environment variable, which is only
// readable through dart:io and therefore unavailable on web.
skip: kIsWeb,
);

test('explicit debug: true still logs under flutter test', () async {
await Supabase.initialize(
url: '',
publishableKey: '',
debug: true,
authOptions: FlutterAuthClientOptions(
localStorage: const MockLocalStorage(),
pkceAsyncStorage: MockAsyncStorage(),
),
);

expect(logs.any((log) => log.contains('Supabase init completed')), isTrue);
});
}
1 change: 1 addition & 0 deletions packages/supabase_flutter/test/dispose_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main() {
await Supabase.initialize(
url: '',
publishableKey: '',
debug: false,
accessToken: () async => 'custom-access-token',
);

Expand Down
12 changes: 12 additions & 0 deletions packages/supabase_flutter/test/initialization_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
Expand All @@ -10,6 +11,10 @@ void main() {
const supabaseUrl = '';
const supabaseKey = '';

setUpAll(() {
debugPrint = (String? message, {int? wrapWidth}) {};
});

group('Supabase initialization', () {
setUp(() {
SharedPreferences.setMockInitialValues({});
Expand All @@ -29,6 +34,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
Comment thread
Vinzent03 marked this conversation as resolved.
Resolved
);
});
});
Expand All @@ -39,6 +45,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
authOptions: const FlutterAuthClientOptions(
localStorage: localStorage,
),
Expand Down Expand Up @@ -66,6 +73,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
authOptions: const FlutterAuthClientOptions(
authFlowType: AuthFlowType.pkce,
),
Expand All @@ -79,6 +87,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
httpClient: httpClient,
);
});
Expand All @@ -87,6 +96,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
accessToken: () async => 'custom-access-token',
);

Expand All @@ -104,6 +114,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
);

// Dispose
Expand All @@ -116,6 +127,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
);
});

Expand Down
1 change: 1 addition & 0 deletions packages/supabase_flutter/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void main() {
await Supabase.initialize(
url: supabaseUrl,
publishableKey: supabaseKey,
debug: false,
authOptions: FlutterAuthClientOptions(
localStorage: const MockLocalStorage(),
pkceAsyncStorage: MockAsyncStorage(),
Expand Down
Loading