Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
buenaflor committed Dec 18, 2024
1 parent a51c318 commit cf41126
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 49 deletions.
4 changes: 2 additions & 2 deletions flutter/lib/src/integrations/native_sdk_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SentryFlutterOptions> createSdkIntegration(
SentryNativeBinding native) {
return NativeSdkIntegration(native);
}

Expand Down
4 changes: 0 additions & 4 deletions flutter/lib/src/integrations/sdk_integration.dart
Original file line number Diff line number Diff line change
@@ -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<SentryFlutterOptions>;
4 changes: 2 additions & 2 deletions flutter/lib/src/integrations/web_sdk_integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<SentryFlutterOptions> createSdkIntegration(
SentryNativeBinding native) {
final scriptLoader = SentryScriptLoader();
return WebSdkIntegration(native, scriptLoader);
}
Expand Down
81 changes: 40 additions & 41 deletions flutter/test/sentry_flutter_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +96,6 @@ void main() {
integrations: options.integrations,
shouldHaveIntegrations: [
...androidIntegrations,
...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
ReplayIntegration,
Expand Down Expand Up @@ -158,7 +153,6 @@ void main() {
integrations: options.integrations,
shouldHaveIntegrations: [
...iOsAndMacOsIntegrations,
...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
ReplayIntegration,
Expand Down Expand Up @@ -211,7 +205,7 @@ void main() {

testConfiguration(integrations: integrations, shouldHaveIntegrations: [
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...platformAgnosticIntegrations,
...nonWebIntegrations,
], shouldNotHaveIntegrations: [
Expand Down Expand Up @@ -264,7 +258,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...webIntegrations,
],
);
Expand Down Expand Up @@ -312,7 +306,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...webIntegrations,
],
);
Expand Down Expand Up @@ -361,7 +355,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...nonWebIntegrations,
],
);
Expand All @@ -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(
Expand All @@ -397,7 +391,7 @@ void main() {
expect(containsRunZonedGuardedIntegration, isFalse);

await Sentry.close();
});
}, testOn: 'browser');

test('Web && (iOS || macOS)', () async {
List<Integration> integrations = [];
Expand Down Expand Up @@ -428,7 +422,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...nonWebIntegrations,
],
);
Expand All @@ -439,7 +433,7 @@ void main() {
afterIntegration: WidgetsFlutterBindingIntegration);

await Sentry.close();
});
}, testOn: 'browser');

test('Web && (macOS)', () async {
List<Integration> integrations = [];
Expand Down Expand Up @@ -470,7 +464,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...nonWebIntegrations,
],
);
Expand All @@ -483,7 +477,7 @@ void main() {
expect(Sentry.currentHub.profilerFactory, isNull);

await Sentry.close();
});
}, testOn: 'browser');

test('Web && Android', () async {
List<Integration> integrations = [];
Expand Down Expand Up @@ -513,7 +507,7 @@ void main() {
shouldNotHaveIntegrations: [
...androidIntegrations,
...iOsAndMacOsIntegrations,
...nativeIntegrations,
// ...nativeIntegrations,
...nonWebIntegrations,
],
);
Expand All @@ -524,7 +518,7 @@ void main() {
afterIntegration: WidgetsFlutterBindingIntegration);

await Sentry.close();
});
}, testOn: 'browser');
});

group('Test ScreenshotIntegration', () {
Expand Down Expand Up @@ -562,11 +556,11 @@ void main() {
test('installed with canvasKit renderer', () async {
List<Integration> 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 {
Expand All @@ -583,16 +577,16 @@ void main() {
true);

await Sentry.close();
}, testOn: 'vm');
}, testOn: 'browser');

test('not installed with html renderer', () async {
List<Integration> 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 {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -651,8 +649,6 @@ void main() {
appRunner: appRunner,
options: sentryFlutterOptions,
);

await Sentry.close();
});
});

Expand Down Expand Up @@ -697,14 +693,19 @@ void main() {
group('exception identifiers', () {
setUp(() async {
loadTestPackage();
});

tearDown(() async {
await Sentry.close();
});

test(
'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,
Expand All @@ -729,8 +730,6 @@ void main() {
isA<DartExceptionTypeIdentifier>(),
),
);

await Sentry.close();
});
});
}
Expand Down Expand Up @@ -761,7 +760,7 @@ void loadTestPackage() {

PlatformChecker getPlatformChecker({
required Platform platform,
bool isWeb = false,
bool isWeb = kIsWeb,
bool isRootZone = true,
}) {
final platformChecker = PlatformChecker(
Expand Down
20 changes: 20 additions & 0 deletions flutter/test/sentry_flutter_util.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,6 +17,18 @@ void testScopeObserver(
expect(actualHasNativeScopeObserver, expectedHasNativeScopeObserver);
}

void expectNativeSdkIntegration(Iterable<Integration> integrations) {
final nativeIntegration = integrations.firstWhereOrNull(
(x) => x.runtimeType.toString() == 'NativeSdkIntegration');
expect(integrations, containsOnce(nativeIntegration));
}

void expectWebSdkIntegration(Iterable<Integration> integrations) {
final nativeIntegration = integrations
.firstWhereOrNull((x) => x.runtimeType.toString() == 'WebSdkIntegration');
expect(integrations, containsOnce(nativeIntegration));
}

void testConfiguration({
required Iterable<Integration> integrations,
required Iterable<Type> shouldHaveIntegrations,
Expand All @@ -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({
Expand Down

0 comments on commit cf41126

Please sign in to comment.