diff --git a/flutter/lib/src/integrations/native_sdk_integration.dart b/flutter/lib/src/integrations/native_sdk_integration.dart index 4ef9e87fb..c9f6ac39f 100644 --- a/flutter/lib/src/integrations/native_sdk_integration.dart +++ b/flutter/lib/src/integrations/native_sdk_integration.dart @@ -4,9 +4,9 @@ import 'package:sentry/sentry.dart'; import '../native/sentry_native_binding.dart'; import '../sentry_flutter_options.dart'; -import 'integrations.dart'; -SdkIntegration createSdkIntegration(SentryNativeBinding native) { +Integration createSdkIntegration( + SentryNativeBinding native) { return NativeSdkIntegration(native); } diff --git a/flutter/lib/src/integrations/sdk_integration.dart b/flutter/lib/src/integrations/sdk_integration.dart index 0904e4653..c0ca43dc0 100644 --- a/flutter/lib/src/integrations/sdk_integration.dart +++ b/flutter/lib/src/integrations/sdk_integration.dart @@ -1,7 +1,3 @@ -import '../../sentry_flutter.dart'; - export 'native_sdk_integration.dart' if (dart.library.html) 'web_sdk_integration.dart' if (dart.library.js_interop) 'web_sdk_integration.dart'; - -typedef SdkIntegration = Integration; diff --git a/flutter/lib/src/integrations/web_sdk_integration.dart b/flutter/lib/src/integrations/web_sdk_integration.dart index 078e4db0d..d84fac5c0 100644 --- a/flutter/lib/src/integrations/web_sdk_integration.dart +++ b/flutter/lib/src/integrations/web_sdk_integration.dart @@ -7,9 +7,9 @@ import '../native/sentry_native_binding.dart'; import '../sentry_flutter_options.dart'; import '../web/script_loader/sentry_script_loader.dart'; import '../web/sentry_js_bundle.dart'; -import 'integrations.dart'; -SdkIntegration createSdkIntegration(SentryNativeBinding native) { +Integration createSdkIntegration( + SentryNativeBinding native) { final scriptLoader = SentryScriptLoader(); return WebSdkIntegration(native, scriptLoader); } diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 1b2d8dbd8..5f775f691 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -1,5 +1,6 @@ // ignore_for_file: invalid_use_of_internal_member +import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -51,11 +52,6 @@ final iOsAndMacOsIntegrations = [ LoadContextsIntegration, ]; -// These should be added to every platform which has a native integration. -final nativeIntegrations = [ - SdkIntegration, // This will automatically resolve to either WebSdkIntegration or NativeSdkIntegration -]; - void main() { TestWidgetsFlutterBinding.ensureInitialized(); late NativeChannelFixture native; @@ -100,7 +96,6 @@ void main() { integrations: options.integrations, shouldHaveIntegrations: [ ...androidIntegrations, - ...nativeIntegrations, ...platformAgnosticIntegrations, ...nonWebIntegrations, ReplayIntegration, @@ -158,7 +153,6 @@ void main() { integrations: options.integrations, shouldHaveIntegrations: [ ...iOsAndMacOsIntegrations, - ...nativeIntegrations, ...platformAgnosticIntegrations, ...nonWebIntegrations, ReplayIntegration, @@ -211,7 +205,7 @@ void main() { testConfiguration(integrations: integrations, shouldHaveIntegrations: [ ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...platformAgnosticIntegrations, ...nonWebIntegrations, ], shouldNotHaveIntegrations: [ @@ -264,7 +258,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...webIntegrations, ], ); @@ -312,7 +306,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...webIntegrations, ], ); @@ -361,7 +355,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...nonWebIntegrations, ], ); @@ -375,7 +369,7 @@ void main() { expect(Sentry.currentHub.profilerFactory, isNull); await Sentry.close(); - }); + }, testOn: 'browser'); test('Web (custom zone)', () async { final sentryFlutterOptions = defaultTestOptions(getPlatformChecker( @@ -397,7 +391,7 @@ void main() { expect(containsRunZonedGuardedIntegration, isFalse); await Sentry.close(); - }); + }, testOn: 'browser'); test('Web && (iOS || macOS)', () async { List integrations = []; @@ -428,7 +422,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...nonWebIntegrations, ], ); @@ -439,7 +433,7 @@ void main() { afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); - }); + }, testOn: 'browser'); test('Web && (macOS)', () async { List integrations = []; @@ -470,7 +464,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...nonWebIntegrations, ], ); @@ -483,7 +477,7 @@ void main() { expect(Sentry.currentHub.profilerFactory, isNull); await Sentry.close(); - }); + }, testOn: 'browser'); test('Web && Android', () async { List integrations = []; @@ -513,7 +507,7 @@ void main() { shouldNotHaveIntegrations: [ ...androidIntegrations, ...iOsAndMacOsIntegrations, - ...nativeIntegrations, + // ...nativeIntegrations, ...nonWebIntegrations, ], ); @@ -524,7 +518,7 @@ void main() { afterIntegration: WidgetsFlutterBindingIntegration); await Sentry.close(); - }); + }, testOn: 'browser'); }); group('Test ScreenshotIntegration', () { @@ -562,11 +556,11 @@ void main() { test('installed with canvasKit renderer', () async { List integrations = []; - final sentryFlutterOptions = defaultTestOptions( - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true)) - ..rendererWrapper = MockRendererWrapper(FlutterRenderer.canvasKit) - ..release = '' - ..dist = ''; + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.iOs())) + ..rendererWrapper = MockRendererWrapper(FlutterRenderer.canvasKit) + ..release = '' + ..dist = ''; await SentryFlutter.init( (options) async { @@ -583,16 +577,16 @@ void main() { true); await Sentry.close(); - }, testOn: 'vm'); + }, testOn: 'browser'); test('not installed with html renderer', () async { List integrations = []; - final sentryFlutterOptions = defaultTestOptions( - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true)) - ..rendererWrapper = MockRendererWrapper(FlutterRenderer.html) - ..release = '' - ..dist = ''; + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.iOs())) + ..rendererWrapper = MockRendererWrapper(FlutterRenderer.html) + ..release = '' + ..dist = ''; await SentryFlutter.init( (options) async { @@ -609,18 +603,22 @@ void main() { false); await Sentry.close(); - }, testOn: 'vm'); + }, testOn: 'browser'); }); group('initial values', () { setUp(() async { loadTestPackage(); + }); + + tearDown(() async { await Sentry.close(); }); test('test that initial values are set correctly', () async { final sentryFlutterOptions = defaultTestOptions( - getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); + getPlatformChecker(platform: MockPlatform.android())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) { @@ -634,15 +632,15 @@ void main() { appRunner: appRunner, options: sentryFlutterOptions, ); - - await Sentry.close(); }); test( 'enablePureDartSymbolication is set to false during SentryFlutter init', () async { final sentryFlutterOptions = defaultTestOptions( - getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); + getPlatformChecker(platform: MockPlatform.android())) + ..methodChannel = native.channel; + SentryFlutter.native = mockNativeBinding(); await SentryFlutter.init( (options) { @@ -651,8 +649,6 @@ void main() { appRunner: appRunner, options: sentryFlutterOptions, ); - - await Sentry.close(); }); }); @@ -697,6 +693,9 @@ void main() { group('exception identifiers', () { setUp(() async { loadTestPackage(); + }); + + tearDown(() async { await Sentry.close(); }); @@ -704,7 +703,9 @@ void main() { 'should add DartExceptionTypeIdentifier and FlutterExceptionTypeIdentifier by default', () async { final actualOptions = defaultTestOptions( - getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); + getPlatformChecker(platform: MockPlatform.android())) + ..methodChannel = native.channel; + await SentryFlutter.init( (options) {}, appRunner: appRunner, @@ -729,8 +730,6 @@ void main() { isA(), ), ); - - await Sentry.close(); }); }); } @@ -761,7 +760,7 @@ void loadTestPackage() { PlatformChecker getPlatformChecker({ required Platform platform, - bool isWeb = false, + bool isWeb = kIsWeb, bool isRootZone = true, }) { final platformChecker = PlatformChecker( diff --git a/flutter/test/sentry_flutter_util.dart b/flutter/test/sentry_flutter_util.dart index 30e195965..dd0c84186 100644 --- a/flutter/test/sentry_flutter_util.dart +++ b/flutter/test/sentry_flutter_util.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/native/native_scope_observer.dart'; @@ -15,6 +17,18 @@ void testScopeObserver( expect(actualHasNativeScopeObserver, expectedHasNativeScopeObserver); } +void expectNativeSdkIntegration(Iterable integrations) { + final nativeIntegration = integrations.firstWhereOrNull( + (x) => x.runtimeType.toString() == 'NativeSdkIntegration'); + expect(integrations, containsOnce(nativeIntegration)); +} + +void expectWebSdkIntegration(Iterable integrations) { + final nativeIntegration = integrations + .firstWhereOrNull((x) => x.runtimeType.toString() == 'WebSdkIntegration'); + expect(integrations, containsOnce(nativeIntegration)); +} + void testConfiguration({ required Iterable integrations, required Iterable shouldHaveIntegrations, @@ -35,6 +49,12 @@ void testConfiguration({ for (final type in shouldNotHaveIntegrations) { expect(integrations, isNot(contains(type))); } + + if (kIsWeb) { + expectWebSdkIntegration(integrations); + } else { + expectNativeSdkIntegration(integrations); + } } void testBefore({