Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add an iOSPlatformChecker param to SentryFlutter.init
  • Loading branch information
rxlabz committed Nov 23, 2020
commit fc06571d67680984eae55301eab63fe4d037df55
19 changes: 15 additions & 4 deletions flutter/lib/src/sentry_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ mixin SentryFlutter {
OptionsConfiguration optionsConfiguration,
Function callback, {
PackageLoader packageLoader = _loadPackageInfo,
iOSPlatformChecker iOSPlatformChecker = _platformChecker,
}) async {
await Sentry.init((options) async {
await _initDefaultValues(options, callback, packageLoader);
await _initDefaultValues(
options,
callback,
packageLoader,
iOSPlatformChecker,
);

await optionsConfiguration(options);
});
Expand All @@ -30,6 +36,7 @@ mixin SentryFlutter {
SentryOptions options,
Function callback,
PackageLoader packageLoader,
iOSPlatformChecker iOSPlatformChecker,
) async {
// it is necessary to initialize Flutter method channels so that
// our plugin can call into the native code.
Expand Down Expand Up @@ -58,7 +65,7 @@ mixin SentryFlutter {

// first step is to install the native integration and set default values,
// so we are able to capture future errors.
_addDefaultIntegrations(options, callback);
_addDefaultIntegrations(options, callback, iOSPlatformChecker);

await _setReleaseAndDist(options, packageLoader);

Expand Down Expand Up @@ -103,6 +110,7 @@ mixin SentryFlutter {
static void _addDefaultIntegrations(
SentryOptions options,
Function callback,
iOSPlatformChecker isIOS,
) {
// the ordering here matters, as we'd like to first start the native integration
// that allow us to send events to the network and then the Flutter integrations.
Expand All @@ -121,8 +129,7 @@ mixin SentryFlutter {
options.addIntegration(isolateErrorIntegration);
}

// TODO: make it testable/mockable
if (Platform.isIOS) {
if (isIOS()) {
options.addIntegration(loadContextsIntegration(options, _channel));
}
// finally the runZonedGuarded, catch any errors in Dart code running
Expand All @@ -145,7 +152,11 @@ mixin SentryFlutter {

typedef PackageLoader = Future<PackageInfo> Function();

typedef iOSPlatformChecker = bool Function();

/// Package info loader.
Future<PackageInfo> _loadPackageInfo() async {
return await PackageInfo.fromPlatform();
}

bool _platformChecker() => Platform.isIOS;
1 change: 1 addition & 0 deletions flutter/test/load_contexts_integrations_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@TestOn('ios')
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
Expand Down
13 changes: 12 additions & 1 deletion flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,20 @@ void main() {

test('Flutter init for mobile will run default configurations', () async {
await SentryFlutter.init(
configurationTester,
getConfigurationTester(false),
callback,
packageLoader: loadTestPackage,
iOSPlatformChecker: () => false,
);
});

test('Flutter init for mobile will run default configurations on ios',
() async {
await SentryFlutter.init(
getConfigurationTester(true),
callback,
packageLoader: loadTestPackage,
iOSPlatformChecker: () => true,
);
});
}
Expand Down
47 changes: 23 additions & 24 deletions flutter/test/sentry_flutter_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,35 @@ import 'package:sentry/sentry.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter/src/file_system_transport.dart';
import 'package:sentry_flutter/src/version.dart';

import 'mocks.dart';

FutureOr<void> configurationTester(
SentryOptions options, {
bool isWeb = false,
}) async {
options.dsn = fakeDsn;
FutureOr<void> Function(SentryOptions) getConfigurationTester(bool onIOS) =>
(SentryOptions options) async {
options.dsn = fakeDsn;

expect(kDebugMode, options.debug);
expect('debug', options.environment);
expect(kDebugMode, options.debug);
expect('debug', options.environment);

expect(true, options.transport is FileSystemTransport);
expect(true, options.transport is FileSystemTransport);

expect(
options.integrations
.where((element) => element == flutterErrorIntegration),
isNotEmpty);
expect(
options.integrations
.where((element) => element == flutterErrorIntegration),
isNotEmpty);

expect(
options.integrations
.where((element) => element == isolateErrorIntegration),
isNotEmpty);
expect(
options.integrations
.where((element) => element == isolateErrorIntegration),
isNotEmpty);

expect(4, options.integrations.length);
expect(onIOS ? 5 : 4, options.integrations.length);

expect(sdkName, options.sdk.name);
expect(sdkVersion, options.sdk.version);
expect('pub:sentry_flutter', options.sdk.packages.last.name);
expect(sdkVersion, options.sdk.packages.last.version);
expect(sdkName, options.sdk.name);
expect(sdkVersion, options.sdk.version);
expect('pub:sentry_flutter', options.sdk.packages.last.name);
expect(sdkVersion, options.sdk.packages.last.version);

expect('packageName@version+buildNumber', options.release);
expect('buildNumber', options.dist);
}
expect('packageName@version+buildNumber', options.release);
expect('buildNumber', options.dist);
};