diff --git a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart index 6c598b1ed5..0bf4c218d5 100644 --- a/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart +++ b/dart/lib/src/event_processor/enricher/io_enricher_event_processor.dart @@ -100,6 +100,9 @@ class IoEnricherEventProcessor implements EnricherEventProcessor { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } } diff --git a/dart/lib/src/event_processor/enricher/io_platform_memory.dart b/dart/lib/src/event_processor/enricher/io_platform_memory.dart index 4acde3f15b..1f4a32987b 100644 --- a/dart/lib/src/event_processor/enricher/io_platform_memory.dart +++ b/dart/lib/src/event_processor/enricher/io_platform_memory.dart @@ -75,6 +75,9 @@ class PlatformMemory { } } catch (e) { options.logger(SentryLevel.warning, "Failed to run process: $e"); + if (options.automatedTestMode) { + rethrow; + } } return null; } diff --git a/dart/lib/src/event_processor/exception/io_exception_event_processor.dart b/dart/lib/src/event_processor/exception/io_exception_event_processor.dart index bb4049c00e..55677a938c 100644 --- a/dart/lib/src/event_processor/exception/io_exception_event_processor.dart +++ b/dart/lib/src/event_processor/exception/io_exception_event_processor.dart @@ -69,6 +69,9 @@ class IoExceptionEventProcessor implements ExceptionEventProcessor { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } return event.copyWith( diff --git a/dart/lib/src/hub.dart b/dart/lib/src/hub.dart index b69bc5056f..2626670a3e 100644 --- a/dart/lib/src/hub.dart +++ b/dart/lib/src/hub.dart @@ -124,6 +124,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } finally { _lastEventId = sentryId; } @@ -183,6 +186,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } finally { _lastEventId = sentryId; } @@ -238,6 +244,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } finally { _lastEventId = sentryId; } @@ -271,6 +280,9 @@ class Hub { exception: exception, stackTrace: stacktrace, ); + if (_options.automatedTestMode) { + rethrow; + } } } @@ -364,6 +376,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } _isEnabled = false; @@ -565,6 +580,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } } } @@ -602,6 +620,9 @@ class Hub { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } } return sentryId; @@ -682,6 +703,9 @@ class _WeakMap { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } } @@ -699,6 +723,9 @@ class _WeakMap { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } return null; } diff --git a/dart/lib/src/load_dart_debug_images_integration.dart b/dart/lib/src/load_dart_debug_images_integration.dart index 81cf7cc679..0932cac9af 100644 --- a/dart/lib/src/load_dart_debug_images_integration.dart +++ b/dart/lib/src/load_dart_debug_images_integration.dart @@ -42,6 +42,9 @@ class _LoadImageIntegrationEventProcessor implements EventProcessor { exception: e, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } return event; } } diff --git a/dart/lib/src/recursive_exception_cause_extractor.dart b/dart/lib/src/recursive_exception_cause_extractor.dart index 7118d98c68..5636af84a5 100644 --- a/dart/lib/src/recursive_exception_cause_extractor.dart +++ b/dart/lib/src/recursive_exception_cause_extractor.dart @@ -41,6 +41,9 @@ class RecursiveExceptionCauseExtractor { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } break; } } diff --git a/dart/lib/src/sentry_baggage.dart b/dart/lib/src/sentry_baggage.dart index b6fc8b7dac..c47cd37624 100644 --- a/dart/lib/src/sentry_baggage.dart +++ b/dart/lib/src/sentry_baggage.dart @@ -55,6 +55,7 @@ class SentryBaggage { exception: exception, stackTrace: stackTrace, ); + // TODO rethrow in options.automatedTestMode (currently not available here to check) } } diff --git a/dart/lib/src/sentry_client.dart b/dart/lib/src/sentry_client.dart index 74bb690eb6..3e1dcaefcf 100644 --- a/dart/lib/src/sentry_client.dart +++ b/dart/lib/src/sentry_client.dart @@ -565,6 +565,7 @@ class SentryClient { count: spanCountBeforeEventProcessors + 1); } _options.logger(SentryLevel.debug, 'Event was dropped by a processor'); + break; } else if (event is SentryTransaction && processedEvent is SentryTransaction) { // If event processor removed only some spans we still report them as dropped diff --git a/dart/lib/src/sentry_envelope_item.dart b/dart/lib/src/sentry_envelope_item.dart index b0f19cfccd..61463cdd8d 100644 --- a/dart/lib/src/sentry_envelope_item.dart +++ b/dart/lib/src/sentry_envelope_item.dart @@ -132,6 +132,7 @@ class SentryEnvelopeItem { // TODO the data copy could be avoided - this would be most significant with attachments. return [...itemHeader, ...newLine, ...data]; } catch (e) { + // TODO rethrow in options.automatedTestMode (currently not available here to check) return []; } } diff --git a/dart/lib/src/transport/http_transport.dart b/dart/lib/src/transport/http_transport.dart index 68950948a2..16cfed654c 100644 --- a/dart/lib/src/transport/http_transport.dart +++ b/dart/lib/src/transport/http_transport.dart @@ -64,6 +64,9 @@ class HttpTransport implements Transport { return eventId != null ? SentryId.fromId(eventId) : null; } catch (e) { _options.logger(SentryLevel.error, 'Error parsing response: $e'); + if (_options.automatedTestMode) { + rethrow; + } return null; } } diff --git a/dart/lib/src/transport/spotlight_http_transport.dart b/dart/lib/src/transport/spotlight_http_transport.dart index e44cae44b9..79de9e5f6e 100644 --- a/dart/lib/src/transport/spotlight_http_transport.dart +++ b/dart/lib/src/transport/spotlight_http_transport.dart @@ -33,6 +33,9 @@ class SpotlightHttpTransport extends Transport { } catch (e) { _options.logger( SentryLevel.warning, 'Failed to send envelope to Spotlight: $e'); + if (_options.automatedTestMode) { + rethrow; + } } return _transport.send(envelope); } diff --git a/dart/test/debug_image_extractor_test.dart b/dart/test/debug_image_extractor_test.dart index 6218c726a9..7a0ad7d12f 100644 --- a/dart/test/debug_image_extractor_test.dart +++ b/dart/test/debug_image_extractor_test.dart @@ -1,9 +1,9 @@ import 'package:test/test.dart'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/debug_image_extractor.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group(DebugImageExtractor, () { @@ -112,8 +112,7 @@ isolate_dso_base: 10000000 class Fixture { DebugImageExtractor getSut({required MockPlatform platform}) { - final options = SentryOptions(dsn: 'https://public@sentry.example.com/1') - ..platformChecker = MockPlatformChecker(platform: platform); + final options = defaultTestOptions(MockPlatformChecker(platform: platform)); return DebugImageExtractor(options); } } diff --git a/dart/test/diagnostic_logger_test.dart b/dart/test/diagnostic_logger_test.dart index ec53421e33..f33baa1643 100644 --- a/dart/test/diagnostic_logger_test.dart +++ b/dart/test/diagnostic_logger_test.dart @@ -2,6 +2,8 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/diagnostic_logger.dart'; import 'package:test/test.dart'; +import 'test_utils.dart'; + void main() { late Fixture fixture; @@ -44,7 +46,7 @@ void main() { } class Fixture { - var options = SentryOptions(); + var options = defaultTestOptions(); Object? loggedMessage; diff --git a/dart/test/environment_test.dart b/dart/test/environment_test.dart index b16225d1dd..d955f931e2 100644 --- a/dart/test/environment_test.dart +++ b/dart/test/environment_test.dart @@ -3,6 +3,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_environment_variables.dart'; +import 'test_utils.dart'; void main() { // See https://docs.sentry.io/platforms/dart/configuration/options/ @@ -13,7 +14,7 @@ void main() { }); test('SentryOptions are not overriden by environment', () async { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.release = 'release-1.2.3'; options.dist = 'foo'; options.environment = 'prod'; @@ -23,28 +24,26 @@ void main() { release: 'release-9.8.7', dist: 'bar', ); - options.automatedTestMode = true; await Sentry.init( (options) => options, options: options, ); - expect(options.dsn, fakeDsn); + expect(options.dsn, testDsn); expect(options.environment, 'prod'); expect(options.release, 'release-1.2.3'); expect(options.dist, 'foo'); }); test('SentryOptions are overriden by environment', () async { - final options = SentryOptions(); + final options = defaultTestOptions()..dsn = null; options.environmentVariables = MockEnvironmentVariables( dsn: fakeDsn, environment: 'staging', release: 'release-9.8.7', dist: 'bar', ); - options.automatedTestMode = true; await Sentry.init( (options) => options, diff --git a/dart/test/event_processor/deduplication_event_processor_test.dart b/dart/test/event_processor/deduplication_event_processor_test.dart index 3e17fe4065..de576bafd4 100644 --- a/dart/test/event_processor/deduplication_event_processor_test.dart +++ b/dart/test/event_processor/deduplication_event_processor_test.dart @@ -6,6 +6,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_hub.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; void main() { group('$DeduplicationEventProcessor', () { @@ -77,14 +78,13 @@ void main() { final transport = MockTransport(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; await Sentry.init( (options) { options.dsn = fakeDsn; options.transport = transport; options.enableDeduplication = true; }, - options: options, + options: defaultTestOptions(), ); // The test doesn't work if `outerTestMethod` is passed as @@ -114,7 +114,7 @@ class Fixture { DeduplicationEventProcessor getSut(bool enabled, [int? maxDeduplicationItems]) { - final options = SentryOptions(dsn: fakeDsn) + final options = defaultTestOptions() ..enableDeduplication = enabled ..maxDeduplicationItems = maxDeduplicationItems ?? 5; diff --git a/dart/test/event_processor/enricher/io_enricher_test.dart b/dart/test/event_processor/enricher/io_enricher_test.dart index dad1a62f6c..a48c8dfed5 100644 --- a/dart/test/event_processor/enricher/io_enricher_test.dart +++ b/dart/test/event_processor/enricher/io_enricher_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import '../../mocks.dart'; import '../../mocks/mock_platform_checker.dart'; +import '../../test_utils.dart'; void main() { group('io_enricher', () { @@ -164,20 +165,17 @@ void main() { }); test('$IoEnricherEventProcessor gets added on init', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; - late SentryOptions configuredOptions; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; - configuredOptions = options; }, options: options, ); await Sentry.close(); - final ioEnricherCount = configuredOptions.eventProcessors - .whereType() - .length; + final ioEnricherCount = + options.eventProcessors.whereType().length; expect(ioEnricherCount, 1); }); }); @@ -188,10 +186,8 @@ class Fixture { bool hasNativeIntegration = false, bool includePii = false, }) { - final options = SentryOptions( - dsn: fakeDsn, - checker: - MockPlatformChecker(hasNativeIntegration: hasNativeIntegration)) + final options = defaultTestOptions( + MockPlatformChecker(hasNativeIntegration: hasNativeIntegration)) ..sendDefaultPii = includePii; return IoEnricherEventProcessor(options); diff --git a/dart/test/event_processor/enricher/io_platform_memory_test.dart b/dart/test/event_processor/enricher/io_platform_memory_test.dart index 0f987b935c..ce2c8474f4 100644 --- a/dart/test/event_processor/enricher/io_platform_memory_test.dart +++ b/dart/test/event_processor/enricher/io_platform_memory_test.dart @@ -3,10 +3,11 @@ library dart_test; import 'dart:io'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/event_processor/enricher/io_platform_memory.dart'; import 'package:test/test.dart'; +import '../../test_utils.dart'; + void main() { late Fixture fixture; @@ -52,7 +53,7 @@ void main() { } class Fixture { - var options = SentryOptions(); + var options = defaultTestOptions(); PlatformMemory getSut() { return PlatformMemory(options); diff --git a/dart/test/event_processor/enricher/web_enricher_test.dart b/dart/test/event_processor/enricher/web_enricher_test.dart index d2590a09fa..39502fc134 100644 --- a/dart/test/event_processor/enricher/web_enricher_test.dart +++ b/dart/test/event_processor/enricher/web_enricher_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; import '../../mocks.dart'; import '../../mocks/mock_platform_checker.dart'; +import '../../test_utils.dart'; // can be tested on command line with // `dart test -p chrome --name web_enricher` @@ -201,9 +202,8 @@ void main() { class Fixture { WebEnricherEventProcessor getSut() { - final options = SentryOptions( - dsn: fakeDsn, - checker: MockPlatformChecker(hasNativeIntegration: false)); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); return enricherEventProcessor(options) as WebEnricherEventProcessor; } } diff --git a/dart/test/exception_identifier_test.dart b/dart/test/exception_identifier_test.dart index b3014203dd..29e2a4a735 100644 --- a/dart/test/exception_identifier_test.dart +++ b/dart/test/exception_identifier_test.dart @@ -4,10 +4,10 @@ import 'package:sentry/src/dart_exception_type_identifier.dart'; import 'package:sentry/src/sentry_exception_factory.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks.mocks.dart'; import 'mocks/mock_transport.dart'; import 'sentry_client_test.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -165,7 +165,7 @@ void main() { } class Fixture { - SentryOptions options = SentryOptions(dsn: fakeDsn); + SentryOptions options = defaultTestOptions(); } // We use this PlaceHolder exception to mimic an obfuscated runtimeType diff --git a/dart/test/http_client/failed_request_client_test.dart b/dart/test/http_client/failed_request_client_test.dart index 2ac9a74c8e..b35dd2957b 100644 --- a/dart/test/http_client/failed_request_client_test.dart +++ b/dart/test/http_client/failed_request_client_test.dart @@ -8,6 +8,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_hub.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; final requestUri = Uri.parse('https://example.com?foo=bar#myFragment'); @@ -359,7 +360,7 @@ MockClient createThrowingClient() { class CloseableMockClient extends Mock implements BaseClient {} class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dart/test/http_client/io_client_provider_test.dart b/dart/test/http_client/io_client_provider_test.dart index 0672e84c08..81d05c1540 100644 --- a/dart/test/http_client/io_client_provider_test.dart +++ b/dart/test/http_client/io_client_provider_test.dart @@ -7,7 +7,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/http_client/io_client_provider.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; void main() { group('getClient', () { @@ -77,7 +77,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final mockHttpClient = MockHttpClient(); String? mockUser; diff --git a/dart/test/http_client/tracing_client_test.dart b/dart/test/http_client/tracing_client_test.dart index 6cefe626b3..4e052dc518 100644 --- a/dart/test/http_client/tracing_client_test.dart +++ b/dart/test/http_client/tracing_client_test.dart @@ -5,8 +5,8 @@ import 'package:sentry/src/http_client/tracing_client.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_transport.dart'; +import '../test_utils.dart'; final requestUri = Uri.parse('https://example.com?foo=bar#baz'); @@ -220,7 +220,7 @@ MockClient createThrowingClient() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dart/test/hub_test.dart b/dart/test/hub_test.dart index c53ab74e48..564c59ff7d 100644 --- a/dart/test/hub_test.dart +++ b/dart/test/hub_test.dart @@ -10,6 +10,7 @@ import 'mocks.dart'; import 'mocks.mocks.dart'; import 'mocks/mock_client_report_recorder.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { bool scopeEquals(Scope? a, Scope b) { @@ -25,7 +26,7 @@ void main() { group('Hub instantiation', () { test('should instantiate with a dsn', () { - final hub = Hub(SentryOptions(dsn: fakeDsn)); + final hub = Hub(defaultTestOptions()); expect(hub.isEnabled, true); }); }); @@ -458,11 +459,11 @@ void main() { }); group('Hub scope', () { - var hub = Hub(SentryOptions(dsn: fakeDsn)); + var hub = Hub(defaultTestOptions()); var client = MockSentryClient(); setUp(() { - hub = Hub(SentryOptions(dsn: fakeDsn)); + hub = Hub(defaultTestOptions()); client = MockSentryClient(); hub.bindClient(client); }); @@ -487,7 +488,7 @@ void main() { expect(client.captureEventCalls.first.scope, isNotNull); final scope = client.captureEventCalls.first.scope; - final otherScope = Scope(SentryOptions(dsn: fakeDsn)) + final otherScope = Scope(defaultTestOptions()) ..level = SentryLevel.debug ..fingerprint = ['1', '2']; @@ -511,7 +512,7 @@ void main() { await hub.captureEvent(fakeEvent); final scope = client.captureEventCalls.first.scope; - final otherScope = Scope(SentryOptions(dsn: fakeDsn)); + final otherScope = Scope(defaultTestOptions()); await otherScope.setUser(fakeUser); expect( @@ -542,6 +543,7 @@ void main() { }); test('captureEvent should handle thrown error in scope callback', () async { + fixture.options.automatedTestMode = false; final hub = fixture.getSut(debug: true); final scopeCallbackException = Exception('error in scope callback'); @@ -557,6 +559,7 @@ void main() { test('captureException should handle thrown error in scope callback', () async { + fixture.options.automatedTestMode = false; final hub = fixture.getSut(debug: true); final scopeCallbackException = Exception('error in scope callback'); @@ -573,6 +576,7 @@ void main() { test('captureMessage should handle thrown error in scope callback', () async { + fixture.options.automatedTestMode = false; final hub = fixture.getSut(debug: true); final scopeCallbackException = Exception('error in scope callback'); @@ -593,7 +597,7 @@ void main() { SentryOptions options; setUp(() { - options = SentryOptions(dsn: fakeDsn); + options = defaultTestOptions(); hub = Hub(options); client = MockSentryClient(); hub.bindClient(client); @@ -756,7 +760,7 @@ class Fixture { final client = MockSentryClient(); final recorder = MockClientReportRecorder(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late SentryTransactionContext _context; late SentryTracer tracer; diff --git a/dart/test/initialization_test.dart b/dart/test/initialization_test.dart index e6f9ddea23..42766ac93d 100644 --- a/dart/test/initialization_test.dart +++ b/dart/test/initialization_test.dart @@ -5,6 +5,7 @@ import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; import 'mocks.dart'; +import 'test_utils.dart'; // Tests for the following issue // https://github.com/getsentry/sentry-dart/issues/508 @@ -15,7 +16,7 @@ void main() { }); test('async re-initilization', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -36,7 +37,7 @@ void main() { // This is the failure from // https://github.com/getsentry/sentry-dart/issues/508 test('re-initilization', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( (options) { options.dsn = fakeDsn; diff --git a/dart/test/load_dart_debug_images_integration_test.dart b/dart/test/load_dart_debug_images_integration_test.dart index 8b10a62328..e7f06525ce 100644 --- a/dart/test/load_dart_debug_images_integration_test.dart +++ b/dart/test/load_dart_debug_images_integration_test.dart @@ -7,6 +7,7 @@ import 'package:test/test.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group(LoadDartDebugImagesIntegration, () { @@ -92,7 +93,7 @@ isolate_dso_base: 10000000 } class Fixture { - final options = SentryOptions(dsn: 'https://public@sentry.example.com/1'); + final options = defaultTestOptions(); Fixture() { final integration = LoadDartDebugImagesIntegration(); diff --git a/dart/test/metrics/metrics_aggregator_test.dart b/dart/test/metrics/metrics_aggregator_test.dart index 5636e7ebf6..19c6a9f184 100644 --- a/dart/test/metrics/metrics_aggregator_test.dart +++ b/dart/test/metrics/metrics_aggregator_test.dart @@ -3,8 +3,8 @@ import 'package:sentry/src/metrics/metric.dart'; import 'package:sentry/src/metrics/metrics_aggregator.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { group('emit', () { @@ -402,6 +402,7 @@ void main() { }); test('emits if it throws', () async { + fixture.options.automatedTestMode = false; final MetricsAggregator sut = fixture.getSut(maxWeight: 4); fixture.options.beforeMetricCallback = (key, {tags}) => throw Exception(); sut.testEmit(key: 'key1'); @@ -455,7 +456,7 @@ const Map mockTags2 = {'tag1': 'val1'}; final DateTime mockTimestamp = DateTime.fromMillisecondsSinceEpoch(1); class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final mockHub = MockHub(); late final hub = Hub(options); diff --git a/dart/test/metrics/metrics_api_test.dart b/dart/test/metrics/metrics_api_test.dart index 8c53e66772..8e18d21996 100644 --- a/dart/test/metrics/metrics_api_test.dart +++ b/dart/test/metrics/metrics_api_test.dart @@ -6,8 +6,8 @@ import 'package:sentry/src/metrics/metrics_api.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { group('api', () { @@ -144,7 +144,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); final mockHub = MockHub(); late final hub = Hub(_options); diff --git a/dart/test/mocks/mock_hub.dart b/dart/test/mocks/mock_hub.dart index c076251736..8fa7d31388 100644 --- a/dart/test/mocks/mock_hub.dart +++ b/dart/test/mocks/mock_hub.dart @@ -3,7 +3,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/metrics/metric.dart'; import 'package:sentry/src/metrics/metrics_aggregator.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; import 'mock_sentry_client.dart'; import 'no_such_method_provider.dart'; @@ -21,7 +21,7 @@ class MockHub with NoSuchMethodProvider implements Hub { int spanContextCals = 0; int getSpanCalls = 0; - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late final MetricsAggregator _metricsAggregator = MetricsAggregator(options: _options, hub: this); diff --git a/dart/test/protocol/rate_limiter_test.dart b/dart/test/protocol/rate_limiter_test.dart index b4364bceff..96d91ea685 100644 --- a/dart/test/protocol/rate_limiter_test.dart +++ b/dart/test/protocol/rate_limiter_test.dart @@ -10,6 +10,7 @@ import 'package:sentry/src/sentry_envelope_header.dart'; import '../mocks/mock_client_report_recorder.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { var fixture = Fixture(); @@ -368,7 +369,7 @@ class Fixture { late var mockRecorder = MockClientReportRecorder(); RateLimiter getSut() { - final options = SentryOptions(); + final options = defaultTestOptions(); options.clock = _currentDateTime; options.recorder = mockRecorder; diff --git a/dart/test/recursive_exception_cause_extractor_test.dart b/dart/test/recursive_exception_cause_extractor_test.dart index e32400b36b..b2da696998 100644 --- a/dart/test/recursive_exception_cause_extractor_test.dart +++ b/dart/test/recursive_exception_cause_extractor_test.dart @@ -2,10 +2,9 @@ import 'package:sentry/src/exception_cause.dart'; import 'package:sentry/src/exception_cause_extractor.dart'; import 'package:sentry/src/recursive_exception_cause_extractor.dart'; import 'package:sentry/src/protocol/mechanism.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:sentry/src/throwable_mechanism.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -91,6 +90,7 @@ void main() { ExceptionBCauseExtractor(), ); + fixture.options.automatedTestMode = false; final sut = fixture.getSut(); final flattened = sut.flatten(errorA, null); @@ -101,7 +101,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); RecursiveExceptionCauseExtractor getSut() { return RecursiveExceptionCauseExtractor(options); diff --git a/dart/test/run_zoned_guarded_integration_test.dart b/dart/test/run_zoned_guarded_integration_test.dart index dd3c2aa0f3..71f87e9d12 100644 --- a/dart/test/run_zoned_guarded_integration_test.dart +++ b/dart/test/run_zoned_guarded_integration_test.dart @@ -4,9 +4,9 @@ library dart_test; import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group(RunZonedGuardedIntegration, () { @@ -77,7 +77,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; RunZonedGuardedIntegration getSut( {required RunZonedGuardedRunner runner, diff --git a/dart/test/scope_test.dart b/dart/test/scope_test.dart index 0059a2e77a..59b42e4227 100644 --- a/dart/test/scope_test.dart +++ b/dart/test/scope_test.dart @@ -8,6 +8,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_scope_observer.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -426,7 +427,7 @@ void main() { tags: const {'etag': '987'}, extra: const {'e-infos': 'abc'}, ); - final scope = Scope(SentryOptions(dsn: fakeDsn)) + final scope = Scope(defaultTestOptions()) ..fingerprint = ['example-dart'] ..transaction = '/example/app' ..level = SentryLevel.warning @@ -454,8 +455,7 @@ void main() { test('apply trace context to event', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..span = fixture.sentryTracer; + final scope = Scope(defaultTestOptions())..span = fixture.sentryTracer; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -473,7 +473,7 @@ void main() { fingerprint: ['event-fingerprint'], breadcrumbs: [eventBreadcrumb], ); - final scope = Scope(SentryOptions(dsn: fakeDsn)) + final scope = Scope(defaultTestOptions()) ..fingerprint = ['example-dart'] ..transaction = '/example/app'; @@ -502,7 +502,7 @@ void main() { operatingSystem: SentryOperatingSystem(name: 'event-os'), ), ); - final scope = Scope(SentryOptions(dsn: fakeDsn)); + final scope = Scope(defaultTestOptions()); await scope.setContexts( SentryDevice.type, SentryDevice(name: 'context-device'), @@ -542,7 +542,7 @@ void main() { test('should apply the scope.contexts values', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)); + final scope = Scope(defaultTestOptions()); await scope.setContexts( SentryDevice.type, SentryDevice(name: 'context-device')); await scope.setContexts(SentryApp.type, SentryApp(name: 'context-app')); @@ -580,8 +580,7 @@ void main() { test('should apply the scope level', () async { final event = SentryEvent(level: SentryLevel.warning); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -590,8 +589,7 @@ void main() { test('should apply the scope transaction from the span', () async { final event = SentryEvent(); - final scope = Scope(SentryOptions(dsn: fakeDsn)) - ..span = fixture.sentryTracer; + final scope = Scope(defaultTestOptions())..span = fixture.sentryTracer; final updatedEvent = await scope.applyToEvent(event, Hint()); @@ -612,7 +610,7 @@ void main() { test('should not apply fingerprint if transaction', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..fingerprint = ['test']; + final scope = Scope(defaultTestOptions())..fingerprint = ['test']; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -621,7 +619,7 @@ void main() { test('should not apply level if transaction', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -630,7 +628,7 @@ void main() { test('apply sampled to trace', () async { var tr = SentryTransaction(fixture.sentryTracer); - final scope = Scope(SentryOptions(dsn: fakeDsn))..level = SentryLevel.error; + final scope = Scope(defaultTestOptions())..level = SentryLevel.error; final updatedTr = await scope.applyToEvent(tr, Hint()); @@ -720,6 +718,7 @@ void main() { test("addBreadcrumb with beforeBreadcrumb error handled ", () async { final exception = Exception("before breadcrumb exception"); + fixture.options.automatedTestMode = false; final sut = fixture.getSut( beforeBreadcrumbCallback: ( Breadcrumb? breadcrumb, @@ -744,6 +743,7 @@ void main() { var numberOfBeforeBreadcrumbCalls = 0; final exception = Exception("before breadcrumb exception"); + fixture.options.automatedTestMode = false; final sut = fixture.getSut( beforeBreadcrumbCallback: ( Breadcrumb? breadcrumb, @@ -776,7 +776,7 @@ void main() { class Fixture { final mockScopeObserver = MockScopeObserver(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final sentryTracer = SentryTracer( SentryTransactionContext( diff --git a/dart/test/sentry_attachment_test.dart b/dart/test/sentry_attachment_test.dart index 578cb5ad9b..267ca62601 100644 --- a/dart/test/sentry_attachment_test.dart +++ b/dart/test/sentry_attachment_test.dart @@ -3,8 +3,8 @@ import 'dart:typed_data'; import 'package:sentry/sentry.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('$SentryAttachment ctor', () { @@ -185,7 +185,7 @@ class Fixture { MockTransport transport = MockTransport(); Hub getSut() { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.transport = transport; return Hub(options); } diff --git a/dart/test/sentry_client_test.dart b/dart/test/sentry_client_test.dart index 282aed74fa..1766148a16 100644 --- a/dart/test/sentry_client_test.dart +++ b/dart/test/sentry_client_test.dart @@ -24,6 +24,7 @@ import 'mocks/mock_hub.dart'; import 'mocks/mock_platform.dart'; import 'mocks/mock_platform_checker.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('SentryClient captures message', () { @@ -1249,11 +1250,13 @@ void main() { }); test('thrown error is handled', () async { + fixture.options.automatedTestMode = false; final exception = Exception("before send exception"); final beforeSendTransactionCallback = (SentryTransaction event) { throw exception; }; + fixture.options.automatedTestMode = false; final client = fixture.getSut( beforeSendTransaction: beforeSendTransactionCallback, debug: true); final fakeTransaction = fixture.fakeTransaction(); @@ -1311,11 +1314,13 @@ void main() { }); test('thrown error is handled', () async { + fixture.options.automatedTestMode = false; final exception = Exception("before send exception"); final beforeSendCallback = (SentryEvent event, Hint hint) { throw exception; }; + fixture.options.automatedTestMode = false; final client = fixture.getSut(beforeSend: beforeSendCallback, debug: true); @@ -1604,7 +1609,13 @@ void main() { }); test('record event processor dropping event', () async { - final client = fixture.getSut(eventProcessor: DropAllEventProcessor()); + bool secondProcessorCalled = false; + fixture.options.addEventProcessor(DropAllEventProcessor()); + fixture.options.addEventProcessor(FunctionEventProcessor((event, hint) { + secondProcessorCalled = true; + return event; + })); + final client = fixture.getSut(); await client.captureEvent(fakeEvent); @@ -1612,6 +1623,7 @@ void main() { DiscardReason.eventProcessor); expect( fixture.recorder.discardedEvents.first.category, DataCategory.error); + expect(secondProcessorCalled, isFalse); }); test('record event processor dropping transaction', () async { @@ -1944,8 +1956,8 @@ class Fixture { final recorder = MockClientReportRecorder(); final transport = MockTransport(); - final options = SentryOptions(dsn: fakeDsn) - ..platformChecker = MockPlatformChecker(platform: MockPlatform.iOS()); + final options = + defaultTestOptions(MockPlatformChecker(platform: MockPlatform.iOS())); late SentryTransactionContext _context; late SentryTracer tracer; diff --git a/dart/test/sentry_envelope_test.dart b/dart/test/sentry_envelope_test.dart index a24cab20c7..7fe59d099d 100644 --- a/dart/test/sentry_envelope_test.dart +++ b/dart/test/sentry_envelope_test.dart @@ -10,6 +10,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { group('SentryEnvelope', () { @@ -51,7 +52,9 @@ void main() { '$expectedHeaderJsonSerialized\n$expectedItemSerialized\n$expectedItemSerialized'); final envelopeData = []; - await sut.envelopeStream(SentryOptions()).forEach(envelopeData.addAll); + await sut + .envelopeStream(defaultTestOptions()) + .forEach(envelopeData.addAll); expect(envelopeData, expected); }); @@ -213,12 +216,12 @@ void main() { final sutEnvelopeData = []; await sut - .envelopeStream(SentryOptions()..maxAttachmentSize = 1) + .envelopeStream(defaultTestOptions()..maxAttachmentSize = 1) .forEach(sutEnvelopeData.addAll); final envelopeData = []; await expectedEnvelopeItem - .envelopeStream(SentryOptions()) + .envelopeStream(defaultTestOptions()) .forEach(envelopeData.addAll); expect(sutEnvelopeData, envelopeData); @@ -238,7 +241,7 @@ void main() { dsn: fakeDsn, ); - final _ = sut.envelopeStream(SentryOptions()).map((e) => e); + final _ = sut.envelopeStream(defaultTestOptions()).map((e) => e); }); }); } diff --git a/dart/test/sentry_envelope_vm_test.dart b/dart/test/sentry_envelope_vm_test.dart index 7854ffccb0..e5f0276704 100644 --- a/dart/test/sentry_envelope_vm_test.dart +++ b/dart/test/sentry_envelope_vm_test.dart @@ -10,6 +10,7 @@ import 'package:sentry/src/sentry_envelope_item_header.dart'; import 'package:test/test.dart'; import 'mocks.dart'; +import 'test_utils.dart'; void main() { group('SentryEnvelopeItem', () { @@ -37,7 +38,7 @@ void main() { final envelopeData = []; await envelope - .envelopeStream(SentryOptions()) + .envelopeStream(defaultTestOptions()) .forEach(envelopeData.addAll); final expectedEnvelopeFile = @@ -62,8 +63,9 @@ void main() { attachments: [attachment], ); - final data = (await envelope.envelopeStream(SentryOptions()).toList()) - .reduce((a, b) => a + b); + final data = + (await envelope.envelopeStream(defaultTestOptions()).toList()) + .reduce((a, b) => a + b); final file = File('test_resources/envelope-no-attachment.envelope'); final jsonStr = await file.readAsString(); diff --git a/dart/test/sentry_exception_factory_test.dart b/dart/test/sentry_exception_factory_test.dart index cca350f2b4..a3129fb8f3 100644 --- a/dart/test/sentry_exception_factory_test.dart +++ b/dart/test/sentry_exception_factory_test.dart @@ -2,7 +2,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_exception_factory.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { final fixture = Fixture(); @@ -284,7 +284,7 @@ isolate_instructions: 7526344980, vm_instructions: 752633f000 } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); SentryExceptionFactory getSut({bool attachStacktrace = true}) { options.attachStacktrace = true; diff --git a/dart/test/sentry_isolate_extension_test.dart b/dart/test/sentry_isolate_extension_test.dart index 626d7e525c..89c6a0fe4b 100644 --- a/dart/test/sentry_isolate_extension_test.dart +++ b/dart/test/sentry_isolate_extension_test.dart @@ -4,11 +4,10 @@ library dart_test; import 'dart:isolate'; import 'package:sentry/src/sentry_isolate_extension.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { group("SentryIsolate", () { @@ -53,7 +52,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; Isolate getSut() { return Isolate.current; diff --git a/dart/test/sentry_isolate_test.dart b/dart/test/sentry_isolate_test.dart index 6d41636303..07347d5585 100644 --- a/dart/test/sentry_isolate_test.dart +++ b/dart/test/sentry_isolate_test.dart @@ -5,12 +5,11 @@ import 'package:sentry/src/hub.dart'; import 'package:sentry/src/protocol/sentry_level.dart'; import 'package:sentry/src/protocol/span_status.dart'; import 'package:sentry/src/sentry_isolate.dart'; -import 'package:sentry/src/sentry_options.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group("SentryIsolate", () { @@ -72,5 +71,5 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; } diff --git a/dart/test/sentry_options_test.dart b/dart/test/sentry_options_test.dart index bb2db9db24..be652ca91c 100644 --- a/dart/test/sentry_options_test.dart +++ b/dart/test/sentry_options_test.dart @@ -4,16 +4,16 @@ import 'package:sentry/src/noop_client.dart'; import 'package:sentry/src/version.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { test('$Client is NoOp', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(NoOpClient(), options.httpClient); }); test('$Client sets a custom client', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final client = Client(); options.httpClient = client; @@ -21,20 +21,20 @@ void main() { }); test('maxBreadcrumbs is 100 by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(100, options.maxBreadcrumbs); }); test('maxBreadcrumbs sets custom maxBreadcrumbs', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.maxBreadcrumbs = 200; expect(200, options.maxBreadcrumbs); }); test('SentryLogger sets a diagnostic logger', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); // ignore: deprecated_member_use_from_same_package expect(options.logger, noOpLogger); // ignore: deprecated_member_use_from_same_package @@ -45,32 +45,32 @@ void main() { }); test('tracesSampler is null by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.tracesSampler, isNull); }); test('tracesSampleRate is null by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.tracesSampleRate, isNull); }); test('isTracingEnabled is disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.isTracingEnabled(), false); }); test('isTracingEnabled is enabled by theres rate', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.tracesSampleRate = 1.0; expect(options.isTracingEnabled(), true); }); test('isTracingEnabled is enabled by theres sampler', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); double? sampler(SentrySamplingContext samplingContext) => 0.0; @@ -98,7 +98,7 @@ void main() { }); test('SentryOptions has sentryClientName set', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.sentryClientName, '${sdkName(options.platformChecker.isWeb)}/$sdkVersion'); @@ -131,39 +131,39 @@ void main() { }); test('Spotlight is disabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.spotlight.enabled, false); }); test('metrics are disabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableMetrics, false); }); test('enableExceptionTypeIdentification is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableExceptionTypeIdentification, true); }); test('default tags for metrics are enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; expect(options.enableDefaultTagsForMetrics, true); }); test('default tags for metrics are disabled if metrics are disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = false; expect(options.enableDefaultTagsForMetrics, false); }); test('default tags for metrics are enabled if metrics are enabled, too', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; options.enableDefaultTagsForMetrics = true; @@ -171,14 +171,14 @@ void main() { }); test('span local metric aggregation is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; expect(options.enableSpanLocalMetricAggregation, true); }); test('span local metric aggregation is disabled if metrics are disabled', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = false; expect(options.enableSpanLocalMetricAggregation, false); @@ -186,7 +186,7 @@ void main() { test('span local metric aggregation is enabled if metrics are enabled, too', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); options.enableMetrics = true; options.enableSpanLocalMetricAggregation = true; @@ -194,7 +194,7 @@ void main() { }); test('enablePureDartSymbolication is enabled by default', () { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); expect(options.enableDartSymbolication, true); }); diff --git a/dart/test/sentry_test.dart b/dart/test/sentry_test.dart index 1b363b99a0..201062ed5d 100644 --- a/dart/test/sentry_test.dart +++ b/dart/test/sentry_test.dart @@ -9,6 +9,7 @@ import 'fake_platform_checker.dart'; import 'mocks.dart'; import 'mocks/mock_integration.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; AppRunner appRunner = () {}; @@ -19,7 +20,7 @@ void main() { var anException = Exception(); setUp(() async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -142,7 +143,7 @@ void main() { }); test('null DSN', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); expect( () async => await Sentry.init( options: options, @@ -155,7 +156,7 @@ void main() { test('appRunner should be optional', () async { expect(Sentry.isEnabled, false); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = fakeDsn, @@ -164,7 +165,7 @@ void main() { }); test('empty DSN', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = '', @@ -175,7 +176,7 @@ void main() { test('empty DSN disables the SDK but runs the integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -188,7 +189,7 @@ void main() { }); test('close disables the SDK', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) => options.dsn = fakeDsn, @@ -212,7 +213,7 @@ void main() { test('should install integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -226,7 +227,7 @@ void main() { test('should add default integrations', () async { late SentryOptions optionsReference; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -250,7 +251,7 @@ void main() { }, onPlatform: {'browser': Skip()}); test('should add only web compatible default integrations', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -266,7 +267,7 @@ void main() { test('should close integrations', () async { final integration = MockIntegration(); - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -282,7 +283,7 @@ void main() { }); test('$DeduplicationEventProcessor is added on init', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -299,7 +300,7 @@ void main() { final completer = Completer(); var completed = false; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); final init = Sentry.init( options: options, (options) { @@ -321,7 +322,7 @@ void main() { }); test('should add DartExceptionTypeIdentifier by default', () async { - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); await Sentry.init( options: options, (options) { @@ -348,7 +349,7 @@ void main() { final completer = Completer(); var completed = false; - final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true; + final options = defaultTestOptions(); final init = Sentry.init( options: options, (options) { @@ -371,12 +372,7 @@ void main() { }); test('options.environment debug', () async { - final sentryOptions = SentryOptions(dsn: fakeDsn) - ..automatedTestMode = true - ..platformChecker = FakePlatformChecker.debugMode(); - - final options = SentryOptions(); - options.automatedTestMode = true; + final sentryOptions = defaultTestOptions(FakePlatformChecker.debugMode()); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -388,9 +384,7 @@ void main() { }); test('options.environment profile', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.profileMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions(FakePlatformChecker.profileMode()); await Sentry.init( (options) { @@ -403,9 +397,7 @@ void main() { }); test('options.environment production (defaultEnvironment)', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.releaseMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions(FakePlatformChecker.releaseMode()); await Sentry.init( (options) { options.dsn = fakeDsn; @@ -417,9 +409,7 @@ void main() { }); test('options.logger is set by setting the debug flag', () async { - final sentryOptions = - SentryOptions(dsn: fakeDsn, checker: FakePlatformChecker.debugMode()) - ..automatedTestMode = true; + final sentryOptions = defaultTestOptions(FakePlatformChecker.debugMode()); await Sentry.init( (options) { @@ -443,7 +433,7 @@ void main() { final fixture = Fixture(); test('throw is handled and logged', () async { - final sentryOptions = SentryOptions(dsn: fakeDsn) + final sentryOptions = defaultTestOptions() ..automatedTestMode = false ..debug = true ..logger = fixture.mockLogger; diff --git a/dart/test/sentry_tracer_test.dart b/dart/test/sentry_tracer_test.dart index ba57aeb405..9bc6410725 100644 --- a/dart/test/sentry_tracer_test.dart +++ b/dart/test/sentry_tracer_test.dart @@ -2,9 +2,9 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_hub.dart'; import 'mocks/mock_sentry_client.dart'; +import 'test_utils.dart'; void main() { group('$SentryTracer', () { @@ -521,7 +521,7 @@ void main() { final newBaggage = SentryBaggage.fromHeader(baggage.value); expect(newBaggage.get('sentry-trace_id'), sut.context.traceId.toString()); - expect(newBaggage.get('sentry-public_key'), 'abc'); + expect(newBaggage.get('sentry-public_key'), 'public'); expect(newBaggage.get('sentry-release'), 'release'); expect(newBaggage.get('sentry-environment'), 'environment'); expect(newBaggage.get('sentry-user_segment'), 'segment'); @@ -595,7 +595,7 @@ void main() { final context = sut.traceContext(); expect(context!.traceId, sut.context.traceId); - expect(context.publicKey, 'abc'); + expect(context.publicKey, 'public'); expect(context.release, 'release'); expect(context.environment, 'environment'); // ignore: deprecated_member_use_from_same_package @@ -608,7 +608,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn) + final options = defaultTestOptions() ..release = 'release' ..environment = 'environment'; diff --git a/dart/test/sentry_traces_sampler_test.dart b/dart/test/sentry_traces_sampler_test.dart index 276897e651..3fbcb85772 100644 --- a/dart/test/sentry_traces_sampler_test.dart +++ b/dart/test/sentry_traces_sampler_test.dart @@ -2,7 +2,7 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_traces_sampler.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; +import 'test_utils.dart'; void main() { late Fixture fixture; @@ -81,6 +81,7 @@ void main() { }); test('tracesSampler exception is handled', () { + fixture.options.automatedTestMode = false; final sut = fixture.getSut(debug: true); final exception = Exception("tracesSampler exception"); @@ -151,7 +152,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); SentryLevel? loggedLevel; Object? loggedException; diff --git a/dart/test/sentry_transaction_test.dart b/dart/test/sentry_transaction_test.dart index 7de0549a13..8457e6eb4d 100644 --- a/dart/test/sentry_transaction_test.dart +++ b/dart/test/sentry_transaction_test.dart @@ -4,6 +4,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_hub.dart'; +import 'test_utils.dart'; void main() { final fixture = Fixture(); @@ -108,7 +109,7 @@ void main() { } class Fixture { - final SentryOptions options = SentryOptions(dsn: fakeDsn); + final SentryOptions options = defaultTestOptions(); late final Hub hub = Hub(options); SentryTransaction getSut(SentryTracer tracer) { diff --git a/dart/test/sentry_user_feedback_test.dart b/dart/test/sentry_user_feedback_test.dart index cb406f65b1..fec01ca5bd 100644 --- a/dart/test/sentry_user_feedback_test.dart +++ b/dart/test/sentry_user_feedback_test.dart @@ -5,6 +5,7 @@ import 'package:test/test.dart'; import 'mocks.dart'; import 'mocks/mock_transport.dart'; +import 'test_utils.dart'; void main() { group('$SentryUserFeedback', () { @@ -141,7 +142,7 @@ void main() { }); test('captureUserFeedback does not throw', () async { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions()..automatedTestMode = false; final transport = ThrowingTransport(); options.transport = transport; final sut = Hub(options); @@ -158,7 +159,7 @@ class Fixture { late MockTransport transport; Hub getSut() { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); transport = MockTransport(); options.transport = transport; return Hub(options); diff --git a/dart/test/stack_trace_test.dart b/dart/test/stack_trace_test.dart index 3636d845a4..f63bc0f227 100644 --- a/dart/test/stack_trace_test.dart +++ b/dart/test/stack_trace_test.dart @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:sentry/sentry.dart'; import 'package:sentry/src/origin.dart'; import 'package:sentry/src/sentry_stack_trace_factory.dart'; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; -import 'mocks.dart'; import 'mocks/mock_platform_checker.dart'; +import 'test_utils.dart'; void main() { group('encodeStackTraceFrame', () { @@ -300,8 +299,7 @@ class Fixture { bool considerInAppFramesByDefault = true, bool isWeb = false, }) { - final options = SentryOptions( - dsn: fakeDsn, checker: MockPlatformChecker(isWebValue: isWeb)); + final options = defaultTestOptions(MockPlatformChecker(isWebValue: isWeb)); inAppIncludes.forEach(options.addInAppInclude); inAppExcludes.forEach(options.addInAppExclude); options.considerInAppFramesByDefault = considerInAppFramesByDefault; diff --git a/dart/test/test_utils.dart b/dart/test/test_utils.dart index c7a0138a76..ec25b32f85 100644 --- a/dart/test/test_utils.dart +++ b/dart/test/test_utils.dart @@ -18,6 +18,11 @@ const String _testDsnWithPath = const String _testDsnWithPort = 'https://public:secret@sentry.example.com:8888/1'; +SentryOptions defaultTestOptions([PlatformChecker? checker]) { + return SentryOptions(dsn: testDsn, checker: checker) + ..automatedTestMode = true; +} + void testHeaders( Map? headers, ClockProvider fakeClockProvider, { @@ -69,7 +74,7 @@ Future testCaptureException( fail('Unexpected request on ${request.method} ${request.url} in HttpMock'); }); - final options = SentryOptions(dsn: testDsn) + final options = defaultTestOptions() ..compressPayload = compressPayload ..clock = fakeClockProvider ..httpClient = httpMock @@ -196,7 +201,7 @@ Future testCaptureException( void runTest({Codec, List?>? gzip, bool isWeb = false}) { test('can parse DSN', () async { - final options = SentryOptions(dsn: testDsn); + final options = defaultTestOptions(); final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -213,7 +218,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); test('can parse DSN without secret', () async { - final options = SentryOptions(dsn: _testDsnWithoutSecret); + final options = defaultTestOptions()..dsn = _testDsnWithoutSecret; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -230,7 +235,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); test('can parse DSN with path', () async { - final options = SentryOptions(dsn: _testDsnWithPath); + final options = defaultTestOptions()..dsn = _testDsnWithPath; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -246,7 +251,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { client.close(); }); test('can parse DSN with port', () async { - final options = SentryOptions(dsn: _testDsnWithPort); + final options = defaultTestOptions()..dsn = _testDsnWithPort; final client = SentryClient(options); final dsn = Dsn.parse(options.dsn!); @@ -277,7 +282,8 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); final client = SentryClient( - SentryOptions(dsn: _testDsnWithoutSecret) + defaultTestOptions() + ..dsn = _testDsnWithoutSecret ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false @@ -331,9 +337,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { }); final client = SentryClient( - SentryOptions( - dsn: testDsn, - ) + defaultTestOptions() ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false @@ -392,9 +396,7 @@ void runTest({Codec, List?>? gzip, bool isWeb = false}) { data: {'foo': 'bar'}, ); - final options = SentryOptions( - dsn: testDsn, - ) + final options = defaultTestOptions() ..httpClient = httpMock ..clock = fakeClockProvider ..compressPayload = false diff --git a/dart/test/transport/http_transport_test.dart b/dart/test/transport/http_transport_test.dart index 90065d89d3..6546cd73eb 100644 --- a/dart/test/transport/http_transport_test.dart +++ b/dart/test/transport/http_transport_test.dart @@ -17,6 +17,7 @@ import 'package:test/test.dart'; import '../mocks.dart'; import '../mocks/mock_client_report_recorder.dart'; import '../mocks/mock_hub.dart'; +import '../test_utils.dart'; void main() { SentryEnvelope givenEnvelope() { @@ -286,9 +287,7 @@ void main() { } class Fixture { - final options = SentryOptions( - dsn: 'https://public:secret@sentry.example.com/1', - ); + final options = defaultTestOptions(); late var clientReportRecorder = MockClientReportRecorder(); diff --git a/dart/test/transport/spotlight_http_transport_test.dart b/dart/test/transport/spotlight_http_transport_test.dart index b23f1fd87f..3e9d742bb1 100644 --- a/dart/test/transport/spotlight_http_transport_test.dart +++ b/dart/test/transport/spotlight_http_transport_test.dart @@ -9,6 +9,7 @@ import 'package:test/scaffolding.dart'; import '../mocks.dart'; import '../mocks/mock_client_report_recorder.dart'; +import '../test_utils.dart'; void main() { group('send to Sentry', () { @@ -52,9 +53,7 @@ void main() { } class Fixture { - final options = SentryOptions( - dsn: 'https://public:secret@sentry.example.com/1', - ); + final options = defaultTestOptions(); late var clientReportRecorder = MockClientReportRecorder(); diff --git a/dart/test/transport/tesk_queue_test.dart b/dart/test/transport/tesk_queue_test.dart index 80dc97161c..af22672d97 100644 --- a/dart/test/transport/tesk_queue_test.dart +++ b/dart/test/transport/tesk_queue_test.dart @@ -1,10 +1,9 @@ import 'dart:async'; -import 'package:sentry/sentry.dart'; import 'package:sentry/src/transport/task_queue.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; +import '../test_utils.dart'; void main() { group("called sync", () { @@ -110,7 +109,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); TaskQueue getSut({required int maxQueueSize}) { return TaskQueue(maxQueueSize, options.logger); diff --git a/dart/test/utils/tracing_utils_test.dart b/dart/test/utils/tracing_utils_test.dart index 96b26b55b1..134997afae 100644 --- a/dart/test/utils/tracing_utils_test.dart +++ b/dart/test/utils/tracing_utils_test.dart @@ -2,8 +2,8 @@ import 'package:sentry/sentry.dart'; import 'package:sentry/src/sentry_tracer.dart'; import 'package:test/test.dart'; -import '../mocks.dart'; import '../mocks/mock_sentry_client.dart'; +import '../test_utils.dart'; void main() { group('$containsTargetOrMatchesRegExp', () { @@ -125,7 +125,7 @@ void main() { addBaggageHeaderFromSpan(sut, headers); expect(headers[baggage!.name], - 'other-vendor-value=foo,sentry-trace_id=${sut.context.traceId},sentry-public_key=abc,sentry-release=release,sentry-environment=environment,sentry-user_segment=segment,sentry-transaction=name,sentry-sample_rate=1,sentry-sampled=true'); + 'other-vendor-value=foo,sentry-trace_id=${sut.context.traceId},sentry-public_key=public,sentry-release=release,sentry-environment=environment,sentry-user_segment=segment,sentry-transaction=name,sentry-sample_rate=1,sentry-sampled=true'); }); }); @@ -167,7 +167,7 @@ class Fixture { ), ); - final _options = SentryOptions(dsn: fakeDsn) + final _options = defaultTestOptions() ..release = 'release' ..environment = 'environment'; diff --git a/dio/test/dio_event_processor_test.dart b/dio/test/dio_event_processor_test.dart index af4a94ab8d..9786828841 100644 --- a/dio/test/dio_event_processor_test.dart +++ b/dio/test/dio_event_processor_test.dart @@ -436,7 +436,7 @@ final requestOptions = RequestOptions( ); class Fixture { - final SentryOptions options = SentryOptions(dsn: fakeDsn); + final SentryOptions options = defaultTestOptions(); // ignore: invalid_use_of_internal_member SentryExceptionFactory get exceptionFactory => options.exceptionFactory; diff --git a/dio/test/mocks.dart b/dio/test/mocks.dart index 30e53c5772..052ab82576 100644 --- a/dio/test/mocks.dart +++ b/dio/test/mocks.dart @@ -3,6 +3,11 @@ import 'package:sentry/src/transport/rate_limiter.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + final fakeException = Exception('Error'); final fakeMessage = SentryMessage( diff --git a/dio/test/mocks/mock_hub.dart b/dio/test/mocks/mock_hub.dart index 377e1efb79..5e896d58d7 100644 --- a/dio/test/mocks/mock_hub.dart +++ b/dio/test/mocks/mock_hub.dart @@ -2,6 +2,7 @@ import 'package:meta/meta.dart'; import 'package:sentry/sentry.dart'; +import '../mocks.dart'; import 'no_such_method_provider.dart'; class MockHub with NoSuchMethodProvider implements Hub { @@ -17,7 +18,7 @@ class MockHub with NoSuchMethodProvider implements Hub { int spanContextCals = 0; int getSpanCalls = 0; - final _options = SentryOptions(dsn: 'fixture-dsn'); + final _options = defaultTestOptions(); @override @internal diff --git a/dio/test/sentry_transformer_test.dart b/dio/test/sentry_transformer_test.dart index ffa793c791..93fd36f138 100644 --- a/dio/test/sentry_transformer_test.dart +++ b/dio/test/sentry_transformer_test.dart @@ -137,7 +137,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/dio/test/tracing_client_adapter_test.dart b/dio/test/tracing_client_adapter_test.dart index f67ec4c14d..680825b34f 100644 --- a/dio/test/tracing_client_adapter_test.dart +++ b/dio/test/tracing_client_adapter_test.dart @@ -183,7 +183,7 @@ MockHttpClientAdapter createThrowingClient() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); Fixture() { diff --git a/drift/test/sentry_database_test.dart b/drift/test/sentry_database_test.dart index 52b0c9ee28..9028889630 100644 --- a/drift/test/sentry_database_test.dart +++ b/drift/test/sentry_database_test.dart @@ -15,6 +15,7 @@ import 'package:sqlite3/open.dart'; import 'mocks/mocks.mocks.dart'; import 'test_database.dart'; +import 'utils.dart'; import 'utils/windows_helper.dart'; void main() { @@ -643,7 +644,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); static final dbName = 'people-drift-impl'; final exception = Exception('fixture-exception'); diff --git a/drift/test/utils.dart b/drift/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/drift/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/file/test/mock_sentry_client.dart b/file/test/mock_sentry_client.dart index 4a4a28142d..8fb4091cd7 100644 --- a/file/test/mock_sentry_client.dart +++ b/file/test/mock_sentry_client.dart @@ -4,6 +4,11 @@ import 'no_such_method_provider.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + class MockSentryClient with NoSuchMethodProvider implements SentryClient { List captureTransactionCalls = []; diff --git a/file/test/sentry_file_extension_test.dart b/file/test/sentry_file_extension_test.dart index d6a0bff5bc..843de96003 100644 --- a/file/test/sentry_file_extension_test.dart +++ b/file/test/sentry_file_extension_test.dart @@ -46,7 +46,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub hub; File getSut({ diff --git a/file/test/sentry_file_test.dart b/file/test/sentry_file_test.dart index 48cf9b5175..8a1731a96c 100644 --- a/file/test/sentry_file_test.dart +++ b/file/test/sentry_file_test.dart @@ -662,7 +662,7 @@ void main() { class Fixture { final client = MockSentryClient(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late Hub hub; SentryFile getSut( diff --git a/file/test/sentry_io_overrides_integration_test.dart b/file/test/sentry_io_overrides_integration_test.dart index 86d5f25d74..5a0dcc23a5 100644 --- a/file/test/sentry_io_overrides_integration_test.dart +++ b/file/test/sentry_io_overrides_integration_test.dart @@ -68,7 +68,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final hub = Hub(options); SentryIOOverridesIntegration getSut() { diff --git a/flutter/lib/src/binding_wrapper.dart b/flutter/lib/src/binding_wrapper.dart index 4d6856861a..862f55f8de 100644 --- a/flutter/lib/src/binding_wrapper.dart +++ b/flutter/lib/src/binding_wrapper.dart @@ -26,6 +26,9 @@ class BindingWrapper { stackTrace: s, logger: 'BindingWrapper', ); + if (_hub.options.automatedTestMode) { + rethrow; + } return null; } } diff --git a/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart b/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart index d939f4b90e..edb5773bbc 100644 --- a/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart +++ b/flutter/lib/src/event_processor/android_platform_exception_event_processor.dart @@ -58,6 +58,9 @@ class AndroidPlatformExceptionEventProcessor implements EventProcessor { exception: e, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } return event; } } diff --git a/flutter/lib/src/event_processor/native_app_start_event_processor.dart b/flutter/lib/src/event_processor/native_app_start_event_processor.dart index a0da42359e..a5d67595bd 100644 --- a/flutter/lib/src/event_processor/native_app_start_event_processor.dart +++ b/flutter/lib/src/event_processor/native_app_start_event_processor.dart @@ -123,6 +123,9 @@ class NativeAppStartEventProcessor implements EventProcessor { } catch (e) { _hub.options.logger(SentryLevel.warning, 'Failed to attach native span to app start transaction: $e'); + if (_hub.options.automatedTestMode) { + rethrow; + } } }); } diff --git a/flutter/lib/src/event_processor/screenshot_event_processor.dart b/flutter/lib/src/event_processor/screenshot_event_processor.dart index 8981afe7b1..2b9c80dc05 100644 --- a/flutter/lib/src/event_processor/screenshot_event_processor.dart +++ b/flutter/lib/src/event_processor/screenshot_event_processor.dart @@ -50,7 +50,6 @@ class ScreenshotEventProcessor implements EventProcessor { exception: exception, stackTrace: stackTrace, ); - // ignore: invalid_use_of_internal_member if (_options.automatedTestMode) { rethrow; } @@ -138,6 +137,9 @@ class ScreenshotEventProcessor implements EventProcessor { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } return null; } diff --git a/flutter/lib/src/file_system_transport.dart b/flutter/lib/src/file_system_transport.dart index 85cc0947a7..e28f81ae78 100644 --- a/flutter/lib/src/file_system_transport.dart +++ b/flutter/lib/src/file_system_transport.dart @@ -3,15 +3,15 @@ import 'dart:typed_data'; import 'package:flutter/services.dart'; -import 'package:sentry/sentry.dart'; +import '../sentry_flutter.dart'; import 'native/sentry_native_binding.dart'; class FileSystemTransport implements Transport { FileSystemTransport(this._native, this._options); final SentryNativeBinding _native; - final SentryOptions _options; + final SentryFlutterOptions _options; @override Future send(SentryEnvelope envelope) async { @@ -28,6 +28,9 @@ class FileSystemTransport implements Transport { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } return SentryId.empty(); } diff --git a/flutter/lib/src/integrations/load_contexts_integration.dart b/flutter/lib/src/integrations/load_contexts_integration.dart index a6ed4effcc..679c7b0e36 100644 --- a/flutter/lib/src/integrations/load_contexts_integration.dart +++ b/flutter/lib/src/integrations/load_contexts_integration.dart @@ -212,6 +212,9 @@ class _LoadContextsIntegrationEventProcessor implements EventProcessor { exception: exception, stackTrace: stackTrace, ); + if (_options.automatedTestMode) { + rethrow; + } } return event; } diff --git a/flutter/lib/src/integrations/load_release_integration.dart b/flutter/lib/src/integrations/load_release_integration.dart index de44876e06..ca8a29d11e 100644 --- a/flutter/lib/src/integrations/load_release_integration.dart +++ b/flutter/lib/src/integrations/load_release_integration.dart @@ -46,6 +46,9 @@ class LoadReleaseIntegration extends Integration { exception: exception, stackTrace: stackTrace, ); + if (options.automatedTestMode) { + rethrow; + } } options.sdk.addIntegration('loadReleaseIntegration'); diff --git a/flutter/lib/src/integrations/native_app_start_integration.dart b/flutter/lib/src/integrations/native_app_start_integration.dart index af747dbf36..2456dd4524 100644 --- a/flutter/lib/src/integrations/native_app_start_integration.dart +++ b/flutter/lib/src/integrations/native_app_start_integration.dart @@ -155,6 +155,9 @@ class NativeAppStartIntegration extends Integration { } catch (e) { _hub.options.logger( SentryLevel.warning, 'Failed to parse native span times: $e'); + if (_hub.options.automatedTestMode) { + rethrow; + } continue; } } diff --git a/flutter/lib/src/integrations/native_sdk_integration.dart b/flutter/lib/src/integrations/native_sdk_integration.dart index ad77711b63..4c7c9a92a4 100644 --- a/flutter/lib/src/integrations/native_sdk_integration.dart +++ b/flutter/lib/src/integrations/native_sdk_integration.dart @@ -29,6 +29,9 @@ class NativeSdkIntegration implements Integration { exception: exception, stackTrace: stackTrace, ); + if (_options?.automatedTestMode ?? false) { + rethrow; + } } } @@ -44,6 +47,9 @@ class NativeSdkIntegration implements Integration { exception: exception, stackTrace: stackTrace, ); + if (_options?.automatedTestMode ?? false) { + rethrow; + } } } } diff --git a/flutter/lib/src/integrations/on_error_integration.dart b/flutter/lib/src/integrations/on_error_integration.dart index d97f561d51..365a3067ab 100644 --- a/flutter/lib/src/integrations/on_error_integration.dart +++ b/flutter/lib/src/integrations/on_error_integration.dart @@ -143,6 +143,9 @@ class PlatformDispatcherWrapper { exception: exception, stackTrace: stacktrace, ); + if (options.automatedTestMode) { + rethrow; + } return false; } return true; diff --git a/flutter/lib/src/native/cocoa/sentry_native_cocoa.dart b/flutter/lib/src/native/cocoa/sentry_native_cocoa.dart index 00728d511d..3c956205ae 100644 --- a/flutter/lib/src/native/cocoa/sentry_native_cocoa.dart +++ b/flutter/lib/src/native/cocoa/sentry_native_cocoa.dart @@ -17,7 +17,7 @@ class SentryNativeCocoa extends SentryNativeChannel { ScreenshotRecorder? _replayRecorder; SentryId? _replayId; - SentryNativeCocoa(super.options, super.channel); + SentryNativeCocoa(super.options); @override Future init(Hub hub) async { diff --git a/flutter/lib/src/native/factory_real.dart b/flutter/lib/src/native/factory_real.dart index 554279a8bc..67af20e2e8 100644 --- a/flutter/lib/src/native/factory_real.dart +++ b/flutter/lib/src/native/factory_real.dart @@ -1,19 +1,16 @@ -import 'package:flutter/services.dart'; - import '../../sentry_flutter.dart'; import 'cocoa/sentry_native_cocoa.dart'; import 'java/sentry_native_java.dart'; import 'sentry_native_binding.dart'; import 'sentry_native_channel.dart'; -SentryNativeBinding createBinding(SentryFlutterOptions options, - {MethodChannel channel = const MethodChannel('sentry_flutter')}) { +SentryNativeBinding createBinding(SentryFlutterOptions options) { final platform = options.platformChecker.platform; if (platform.isIOS || platform.isMacOS) { - return SentryNativeCocoa(options, channel); + return SentryNativeCocoa(options); } else if (platform.isAndroid) { - return SentryNativeJava(options, channel); + return SentryNativeJava(options); } else { - return SentryNativeChannel(options, channel); + return SentryNativeChannel(options); } } diff --git a/flutter/lib/src/native/factory_web.dart b/flutter/lib/src/native/factory_web.dart index a928271d16..17c3f5afe0 100644 --- a/flutter/lib/src/native/factory_web.dart +++ b/flutter/lib/src/native/factory_web.dart @@ -1,10 +1,7 @@ -import 'package:flutter/services.dart'; - import '../../sentry_flutter.dart'; import 'sentry_native_binding.dart'; // This isn't actually called, see SentryFlutter.init() -SentryNativeBinding createBinding(SentryFlutterOptions options, - {MethodChannel channel = const MethodChannel('sentry_flutter')}) { +SentryNativeBinding createBinding(SentryFlutterOptions options) { throw UnsupportedError("Native binding is not supported on this platform."); } diff --git a/flutter/lib/src/native/java/sentry_native_java.dart b/flutter/lib/src/native/java/sentry_native_java.dart index 5890ca5db4..94c29fca16 100644 --- a/flutter/lib/src/native/java/sentry_native_java.dart +++ b/flutter/lib/src/native/java/sentry_native_java.dart @@ -16,7 +16,7 @@ class SentryNativeJava extends SentryNativeChannel { ScheduledScreenshotRecorder? _replayRecorder; String? _replayCacheDir; _IdleFrameFiller? _idleFrameFiller; - SentryNativeJava(super.options, super.channel); + SentryNativeJava(super.options); @override Future init(Hub hub) async { @@ -139,7 +139,6 @@ class SentryNativeJava extends SentryNativeChannel { exception: error, stackTrace: stackTrace, ); - // ignore: invalid_use_of_internal_member if (options.automatedTestMode) { rethrow; } diff --git a/flutter/lib/src/native/sentry_native_channel.dart b/flutter/lib/src/native/sentry_native_channel.dart index ce5f063d37..4b2fa464e8 100644 --- a/flutter/lib/src/native/sentry_native_channel.dart +++ b/flutter/lib/src/native/sentry_native_channel.dart @@ -25,8 +25,8 @@ class SentryNativeChannel @protected final SentrySafeMethodChannel channel; - SentryNativeChannel(this.options, MethodChannel channel) - : channel = SentrySafeMethodChannel(channel, options); + SentryNativeChannel(this.options) + : channel = SentrySafeMethodChannel(options); @override Future init(Hub hub) async { diff --git a/flutter/lib/src/native/sentry_native_invoker.dart b/flutter/lib/src/native/sentry_native_invoker.dart index dbda8c4513..0c0a637601 100644 --- a/flutter/lib/src/native/sentry_native_invoker.dart +++ b/flutter/lib/src/native/sentry_native_invoker.dart @@ -15,7 +15,6 @@ mixin SentryNativeSafeInvoker { return await fn(); } catch (error, stackTrace) { _logError(nativeMethodName, error, stackTrace); - // ignore: invalid_use_of_internal_member if (options.automatedTestMode) { rethrow; } @@ -28,7 +27,6 @@ mixin SentryNativeSafeInvoker { return fn(); } catch (error, stackTrace) { _logError(nativeMethodName, error, stackTrace); - // ignore: invalid_use_of_internal_member if (options.automatedTestMode) { rethrow; } diff --git a/flutter/lib/src/native/sentry_safe_method_channel.dart b/flutter/lib/src/native/sentry_safe_method_channel.dart index 8cd258c8dc..184843279d 100644 --- a/flutter/lib/src/native/sentry_safe_method_channel.dart +++ b/flutter/lib/src/native/sentry_safe_method_channel.dart @@ -12,7 +12,7 @@ class SentrySafeMethodChannel with SentryNativeSafeInvoker { final MethodChannel _channel; - SentrySafeMethodChannel(this._channel, this.options); + SentrySafeMethodChannel(this.options) : _channel = options.methodChannel; void setMethodCallHandler( Future Function(MethodCall call)? handler) => diff --git a/flutter/lib/src/navigation/sentry_navigator_observer.dart b/flutter/lib/src/navigation/sentry_navigator_observer.dart index db91098407..48b1059258 100644 --- a/flutter/lib/src/navigation/sentry_navigator_observer.dart +++ b/flutter/lib/src/navigation/sentry_navigator_observer.dart @@ -331,6 +331,9 @@ class SentryNavigatorObserver extends RouteObserver> { exception: exception, stackTrace: stacktrace, ); + if (_hub.options.automatedTestMode) { + rethrow; + } } finally { await transaction?.finish(); if (clearAfter) { @@ -379,6 +382,9 @@ class SentryNavigatorObserver extends RouteObserver> { exception: exception, stackTrace: stacktrace, ); + if (_hub.options.automatedTestMode) { + rethrow; + } } finally { _clear(); } diff --git a/flutter/lib/src/replay/recorder.dart b/flutter/lib/src/replay/recorder.dart index a1f4ea1a0b..847c3a75f6 100644 --- a/flutter/lib/src/replay/recorder.dart +++ b/flutter/lib/src/replay/recorder.dart @@ -103,7 +103,6 @@ class ScreenshotRecorder { } catch (e, stackTrace) { options.logger(SentryLevel.error, "Replay: failed to capture screenshot.", exception: e, stackTrace: stackTrace); - // ignore: invalid_use_of_internal_member if (options.automatedTestMode) { rethrow; } diff --git a/flutter/lib/src/sentry_flutter.dart b/flutter/lib/src/sentry_flutter.dart index 6d035b3740..16e6d7a4d7 100644 --- a/flutter/lib/src/sentry_flutter.dart +++ b/flutter/lib/src/sentry_flutter.dart @@ -51,23 +51,15 @@ mixin SentryFlutter { static Future init( FlutterOptionsConfiguration optionsConfiguration, { AppRunner? appRunner, - @internal PlatformChecker? platformChecker, - @internal RendererWrapper? rendererWrapper, + @internal SentryFlutterOptions? options, }) async { - final flutterOptions = SentryFlutterOptions(); + options ??= SentryFlutterOptions(); // ignore: invalid_use_of_internal_member - sentrySetupStartTime ??= flutterOptions.clock(); + sentrySetupStartTime ??= options.clock(); - if (platformChecker != null) { - flutterOptions.platformChecker = platformChecker; - } - if (rendererWrapper != null) { - flutterOptions.rendererWrapper = rendererWrapper; - } - - if (flutterOptions.platformChecker.hasNativeIntegration) { - _native = createBinding(flutterOptions); + if (options.platformChecker.hasNativeIntegration) { + _native = createBinding(options); } final platformDispatcher = PlatformDispatcher.instance; @@ -76,34 +68,31 @@ mixin SentryFlutter { // Flutter Web don't capture [Future] errors if using [PlatformDispatcher.onError] and not // the [runZonedGuarded]. // likely due to https://github.com/flutter/flutter/issues/100277 - final isOnErrorSupported = flutterOptions.platformChecker.isWeb + final isOnErrorSupported = options.platformChecker.isWeb ? false - : wrapper.isOnErrorSupported(flutterOptions); + : wrapper.isOnErrorSupported(options); - final runZonedGuardedOnError = flutterOptions.platformChecker.isWeb - ? _createRunZonedGuardedOnError() - : null; + final runZonedGuardedOnError = + options.platformChecker.isWeb ? _createRunZonedGuardedOnError() : null; // first step is to install the native integration and set default values, // so we are able to capture future errors. - final defaultIntegrations = _createDefaultIntegrations( - flutterOptions, - isOnErrorSupported, - ); + final defaultIntegrations = + _createDefaultIntegrations(options, isOnErrorSupported); for (final defaultIntegration in defaultIntegrations) { - flutterOptions.addIntegration(defaultIntegration); + options.addIntegration(defaultIntegration); } - await _initDefaultValues(flutterOptions); + await _initDefaultValues(options); await Sentry.init( - (options) { - assert(options == flutterOptions); - return optionsConfiguration(options as SentryFlutterOptions); + (o) { + assert(options == o); + return optionsConfiguration(o as SentryFlutterOptions); }, appRunner: appRunner, // ignore: invalid_use_of_internal_member - options: flutterOptions, + options: options, // ignore: invalid_use_of_internal_member callAppRunnerInRunZonedGuarded: !isOnErrorSupported, // ignore: invalid_use_of_internal_member @@ -117,8 +106,7 @@ mixin SentryFlutter { // Insert it at the start of the list, before the Dart Exceptions that are set in Sentry.init // so we can identify Flutter exceptions first. - flutterOptions - .prependExceptionTypeIdentifier(FlutterExceptionTypeIdentifier()); + options.prependExceptionTypeIdentifier(FlutterExceptionTypeIdentifier()); } static Future _initDefaultValues(SentryFlutterOptions options) async { diff --git a/flutter/lib/src/sentry_flutter_options.dart b/flutter/lib/src/sentry_flutter_options.dart index 18b9d8c919..8e533e4384 100644 --- a/flutter/lib/src/sentry_flutter_options.dart +++ b/flutter/lib/src/sentry_flutter_options.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:file/file.dart'; import 'package:file/local.dart'; +import 'package:flutter/services.dart'; import 'package:meta/meta.dart' as meta; import 'package:sentry/sentry.dart'; import 'package:flutter/widgets.dart'; @@ -224,6 +225,9 @@ class SentryFlutterOptions extends SentryOptions { @meta.internal late RendererWrapper rendererWrapper = RendererWrapper(); + @meta.internal + late MethodChannel methodChannel = const MethodChannel('sentry_flutter'); + /// Enables the View Hierarchy feature. /// /// Renders an ASCII represention of the entire view hierarchy of the @@ -346,6 +350,17 @@ class SentryFlutterOptions extends SentryOptions { /// The [navigatorKey] is used to add information of the currently used locale to the contexts. GlobalKey? navigatorKey; + // Override so we don't have to add `ignore` on each use. + @meta.internal + @override + // ignore: invalid_use_of_internal_member + bool get automatedTestMode => super.automatedTestMode; + + @meta.internal + @override + // ignore: invalid_use_of_internal_member + set automatedTestMode(bool value) => super.automatedTestMode = value; + @meta.internal FileSystem fileSystem = LocalFileSystem(); diff --git a/flutter/temp/native-test/dist/sentry.dll b/flutter/temp/native-test/dist/sentry.dll new file mode 100644 index 0000000000..21615e9b7d Binary files /dev/null and b/flutter/temp/native-test/dist/sentry.dll differ diff --git a/flutter/test/android_platform_exception_event_processor_test.dart b/flutter/test/android_platform_exception_event_processor_test.dart index 9ebae071c7..25ea8b2c6b 100644 --- a/flutter/test/android_platform_exception_event_processor_test.dart +++ b/flutter/test/android_platform_exception_event_processor_test.dart @@ -209,8 +209,7 @@ class Fixture { name: 'main', ); - SentryFlutterOptions options = SentryFlutterOptions(dsn: fakeDsn) - ..attachThreads = true; + SentryFlutterOptions options = defaultTestOptions()..attachThreads = true; } final detailsAndStackTracePlatformException = PlatformException( diff --git a/flutter/test/event_processor/flutter_enricher_event_processor_test.dart b/flutter/test/event_processor/flutter_enricher_event_processor_test.dart index 892e7ff517..0873bd3b22 100644 --- a/flutter/test/event_processor/flutter_enricher_event_processor_test.dart +++ b/flutter/test/event_processor/flutter_enricher_event_processor_test.dart @@ -368,18 +368,14 @@ void main() { testWidgets('$FlutterEnricherEventProcessor gets added on init', (tester) async { - late SentryFlutterOptions sentryOptions; + // use a mockplatform checker so that we don't need to mock platform channels + final sentryOptions = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); + loadTestPackage(); await SentryFlutter.init((options) { options.dsn = fakeDsn; - sentryOptions = options; - }, - appRunner: () {}, - // use a mockplatform checker so that - // we don't need to mock platform channels - platformChecker: MockPlatformChecker( - hasNativeIntegration: false, - )); + }, appRunner: () {}, options: sentryOptions); await Sentry.close(); final ioEnricherCount = sentryOptions.eventProcessors @@ -421,10 +417,8 @@ class Fixture { hasNativeIntegration: hasNativeIntegration, ); - final options = SentryFlutterOptions( - dsn: fakeDsn, - checker: platformChecker, - )..reportPackages = reportPackages; + final options = defaultTestOptions(platformChecker) + ..reportPackages = reportPackages; final customizedOptions = optionsBuilder?.call(options) ?? options; return FlutterEnricherEventProcessor(customizedOptions); } diff --git a/flutter/test/event_processor/screenshot_event_processor_test.dart b/flutter/test/event_processor/screenshot_event_processor_test.dart index 819e3b9b7b..f2ce37396b 100644 --- a/flutter/test/event_processor/screenshot_event_processor_test.dart +++ b/flutter/test/event_processor/screenshot_event_processor_test.dart @@ -140,6 +140,7 @@ void main() { testWidgets('does add screenshot if beforeScreenshot throws', (tester) async { + fixture.options.automatedTestMode = false; fixture.options.beforeScreenshot = (SentryEvent event, {Hint? hint}) { throw Error(); }; @@ -149,6 +150,7 @@ void main() { testWidgets('does add screenshot if async beforeScreenshot throws', (tester) async { + fixture.options.automatedTestMode = false; fixture.options.beforeScreenshot = (SentryEvent event, {Hint? hint}) async { await Future.delayed(Duration(milliseconds: 1)); @@ -180,7 +182,7 @@ void main() { class Fixture { late Hub hub; - SentryFlutterOptions options = SentryFlutterOptions(dsn: fakeDsn); + SentryFlutterOptions options = defaultTestOptions(); Fixture() { options.attachScreenshot = true; diff --git a/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart b/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart index 22708b95bb..186858888d 100644 --- a/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart +++ b/flutter/test/event_processor/url_filter/io_filter_event_processor_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart'; +import '../../mocks.dart'; + void main() { group("ignore allowUrls and denyUrls for non Web", () { late Fixture fixture; @@ -32,7 +34,7 @@ void main() { } class Fixture { - SentryFlutterOptions options = SentryFlutterOptions(); + SentryFlutterOptions options = defaultTestOptions(); UrlFilterEventProcessor getSut() { return UrlFilterEventProcessor(options); } diff --git a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart index 5fb5f7039d..bc80d45e6b 100644 --- a/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart +++ b/flutter/test/event_processor/url_filter/web_url_filter_event_processor_test.dart @@ -5,6 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/url_filter/url_filter_event_processor.dart'; +import '../../mocks.dart'; + // can be tested on command line with // `flutter test --platform=chrome test/event_processor/url_filter/web_url_filter_event_processor_test.dart` // The URL looks something like this: http://localhost:58551/event_processor/url_filter/web_url_filter_event_processor_test.html @@ -112,7 +114,7 @@ void main() { } class Fixture { - SentryFlutterOptions options = SentryFlutterOptions(); + SentryFlutterOptions options = defaultTestOptions(); UrlFilterEventProcessor getSut() { return UrlFilterEventProcessor(options); } diff --git a/flutter/test/file_system_transport_test.dart b/flutter/test/file_system_transport_test.dart index 5aa0713183..84bef4babe 100644 --- a/flutter/test/file_system_transport_test.dart +++ b/flutter/test/file_system_transport_test.dart @@ -40,6 +40,7 @@ void main() { }); test('$FileSystemTransport returns emptyId if channel throws', () async { + fixture.options.automatedTestMode = false; when(fixture.binding.captureEnvelope(any, false)).thenThrow(Exception()); final transport = fixture.getSut(); @@ -155,7 +156,7 @@ void main() { } class Fixture { - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); FileSystemTransport getSut() { diff --git a/flutter/test/initialization_test.dart b/flutter/test/initialization_test.dart index 7b59c173bf..d36e549339 100644 --- a/flutter/test/initialization_test.dart +++ b/flutter/test/initialization_test.dart @@ -10,52 +10,22 @@ import 'mocks.dart'; // https://github.com/getsentry/sentry-dart/issues/508 // There are no asserts, test are succesfull if no exceptions are thrown. void main() { - setUp(() async { - await Sentry.close(); - }); - - test('async re-initilization', () async { - await SentryFlutter.init( - (options) { - options.dsn = fakeDsn; - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - }, - ); - - await Sentry.close(); + final native = NativeChannelFixture(); - await SentryFlutter.init( - (options) { - options.dsn = fakeDsn; - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - }, - ); + void optionsInitializer(SentryFlutterOptions options) { + // LoadReleaseIntegration throws because package_info channel is not available + options.removeIntegration( + options.integrations.firstWhere((i) => i is LoadReleaseIntegration)); + } - await Sentry.close(); - }); - - // This is the failure from - // https://github.com/getsentry/sentry-dart/issues/508 - test('re-initilization', () async { - await SentryFlutter.init( - (options) { - options.dsn = fakeDsn; - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - }, - ); + test('async re-initilization', () async { + await SentryFlutter.init(optionsInitializer, + options: defaultTestOptions()..methodChannel = native.channel); await Sentry.close(); - await SentryFlutter.init( - (options) { - options.dsn = fakeDsn; - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - }, - ); + await SentryFlutter.init(optionsInitializer, + options: defaultTestOptions()..methodChannel = native.channel); await Sentry.close(); }); diff --git a/flutter/test/integrations/connectivity_integration_test.dart b/flutter/test/integrations/connectivity_integration_test.dart index 2f0781e9ec..ed7ca80345 100644 --- a/flutter/test/integrations/connectivity_integration_test.dart +++ b/flutter/test/integrations/connectivity_integration_test.dart @@ -3,7 +3,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/connectivity/connectivity_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -48,7 +47,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); ConnectivityIntegration getSut() { return ConnectivityIntegration(); diff --git a/flutter/test/integrations/debug_print_integration_test.dart b/flutter/test/integrations/debug_print_integration_test.dart index b7804abeeb..67359ade71 100644 --- a/flutter/test/integrations/debug_print_integration_test.dart +++ b/flutter/test/integrations/debug_print_integration_test.dart @@ -94,10 +94,8 @@ class Fixture { bool debug = false, bool enablePrintBreadcrumbs = true, }) { - return SentryFlutterOptions( - dsn: fakeDsn, - checker: MockPlatformChecker(isDebug: debug), - )..enablePrintBreadcrumbs = enablePrintBreadcrumbs; + return defaultTestOptions(MockPlatformChecker(isDebug: debug)) + ..enablePrintBreadcrumbs = enablePrintBreadcrumbs; } DebugPrintIntegration getSut() { diff --git a/flutter/test/integrations/fixture.dart b/flutter/test/integrations/fixture.dart index 19a5ed7904..471c6e42b8 100644 --- a/flutter/test/integrations/fixture.dart +++ b/flutter/test/integrations/fixture.dart @@ -9,13 +9,10 @@ import '../mocks.mocks.dart'; class IntegrationTestFixture { late T sut; late Hub hub; - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); IntegrationTestFixture(T Function(SentryNativeBinding) factory) { - // ignore: invalid_use_of_internal_member - options.automatedTestMode = true; - hub = Hub(options); sut = factory(binding); } diff --git a/flutter/test/integrations/flutter_error_integration_test.dart b/flutter/test/integrations/flutter_error_integration_test.dart index 40a8ef7c36..4ec10025cb 100644 --- a/flutter/test/integrations/flutter_error_integration_test.dart +++ b/flutter/test/integrations/flutter_error_integration_test.dart @@ -269,6 +269,14 @@ void main() { final hub = Hub(fixture.options); final client = MockSentryClient(); + when(client.captureEvent(any, + scope: anyNamed('scope'), + stackTrace: anyNamed('stackTrace'), + hint: anyNamed('hint'))) + .thenAnswer((_) => Future.value(SentryId.newId())); + when(client.captureTransaction(any, + scope: anyNamed('scope'), traceContext: anyNamed('traceContext'))) + .thenAnswer((_) => Future.value(SentryId.newId())); hub.bindClient(client); final sut = fixture.getSut(); @@ -307,7 +315,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; FlutterErrorIntegration getSut() { return FlutterErrorIntegration(); diff --git a/flutter/test/integrations/init_native_sdk_test.dart b/flutter/test/integrations/init_native_sdk_test.dart index 46b64a545b..2c9680b3c2 100644 --- a/flutter/test/integrations/init_native_sdk_test.dart +++ b/flutter/test/integrations/init_native_sdk_test.dart @@ -195,10 +195,7 @@ MethodChannel createChannelWithCallback( SentryFlutterOptions createOptions() { final mockPlatformChecker = MockPlatformChecker(hasNativeIntegration: true); - final options = SentryFlutterOptions( - dsn: fakeDsn, - checker: mockPlatformChecker, - ); + final options = defaultTestOptions(mockPlatformChecker); options.sdk = SdkVersion( name: sdkName, version: sdkVersion, @@ -209,8 +206,8 @@ SentryFlutterOptions createOptions() { class Fixture { late SentryFlutterOptions options; - SentryNativeChannel getSut(MethodChannel native) { - options = createOptions(); - return SentryNativeChannel(options, native); + SentryNativeChannel getSut(MethodChannel channel) { + options = createOptions()..methodChannel = channel; + return SentryNativeChannel(options); } } diff --git a/flutter/test/integrations/load_contexts_integrations_test.dart b/flutter/test/integrations/load_contexts_integrations_test.dart index a1490b8212..7add3f7929 100644 --- a/flutter/test/integrations/load_contexts_integrations_test.dart +++ b/flutter/test/integrations/load_contexts_integrations_test.dart @@ -6,6 +6,7 @@ import 'package:mockito/mockito.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/load_contexts_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -424,7 +425,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); final binding = MockSentryNativeBinding(); LoadContextsIntegration getSut( diff --git a/flutter/test/integrations/load_release_integration_test.dart b/flutter/test/integrations/load_release_integration_test.dart index 0af572bd8b..3d089b03d9 100644 --- a/flutter/test/integrations/load_release_integration_test.dart +++ b/flutter/test/integrations/load_release_integration_test.dart @@ -143,7 +143,7 @@ void main() { } class Fixture { - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); LoadReleaseIntegration getIntegration({Function? loader}) { if (loader != null) { diff --git a/flutter/test/integrations/native_sdk_integration_test.dart b/flutter/test/integrations/native_sdk_integration_test.dart index 5c244b3d66..7c25cec7b7 100644 --- a/flutter/test/integrations/native_sdk_integration_test.dart +++ b/flutter/test/integrations/native_sdk_integration_test.dart @@ -24,13 +24,22 @@ void main() { verify(fixture.binding.init(any)).called(1); }); - test('do not throw', () async { + test('does not throw', () async { + fixture.options.automatedTestMode = false; + fixture.sut = NativeSdkIntegration(_ThrowingMockSentryNative()); await fixture.registerIntegration(); expect(fixture.options.sdk.integrations.contains('nativeSdkIntegration'), false); }); + test('rethrows in tests', () async { + fixture.sut = NativeSdkIntegration(_ThrowingMockSentryNative()); + expect(fixture.registerIntegration, throwsException); + expect(fixture.options.sdk.integrations.contains('nativeSdkIntegration'), + false); + }); + test('closes native SDK', () async { await fixture.registerIntegration(); await fixture.sut.close(); @@ -50,9 +59,9 @@ void main() { verifyNever(fixture.binding.close()); }); - test(' is not added in case of an exception', () async { + test('is not added in case of an exception', () async { fixture.sut = NativeSdkIntegration(_ThrowingMockSentryNative()); - await fixture.registerIntegration(); + expect(fixture.registerIntegration, throwsException); expect(fixture.options.sdk.integrations, []); }); }); diff --git a/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart b/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart index 41de1e557e..6df7df0d0f 100644 --- a/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart +++ b/flutter/test/integrations/not_initialized_widgets_binding_on_error_integration_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/on_error_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -51,7 +50,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final platformDispatcherWrapper = PlatformDispatcherWrapper(MockPlatformDispatcher()); diff --git a/flutter/test/integrations/not_initialized_widgets_binding_test.dart b/flutter/test/integrations/not_initialized_widgets_binding_test.dart index 50c8b22b49..702071d106 100644 --- a/flutter/test/integrations/not_initialized_widgets_binding_test.dart +++ b/flutter/test/integrations/not_initialized_widgets_binding_test.dart @@ -1,7 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/widgets_binding_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; /// Tests that require `WidgetsFlutterBinding.ensureInitialized();` not @@ -25,5 +25,5 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); } diff --git a/flutter/test/integrations/on_error_integration_test.dart b/flutter/test/integrations/on_error_integration_test.dart index fb08e68a9b..f367916612 100644 --- a/flutter/test/integrations/on_error_integration_test.dart +++ b/flutter/test/integrations/on_error_integration_test.dart @@ -2,7 +2,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/integrations/on_error_integration.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import '../mocks.dart'; import '../mocks.mocks.dart'; @@ -165,6 +164,14 @@ void main() { final hub = Hub(fixture.options); final client = MockSentryClient(); + when(client.captureEvent(any, + scope: anyNamed('scope'), + stackTrace: anyNamed('stackTrace'), + hint: anyNamed('hint'))) + .thenAnswer((_) => Future.value(SentryId.newId())); + when(client.captureTransaction(any, + scope: anyNamed('scope'), traceContext: anyNamed('traceContext'))) + .thenAnswer((_) => Future.value(SentryId.newId())); hub.bindClient(client); final sut = fixture.getSut(); @@ -187,7 +194,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final platformDispatcherWrapper = PlatformDispatcherWrapper(MockPlatformDispatcher()); diff --git a/flutter/test/integrations/screenshot_integration_test.dart b/flutter/test/integrations/screenshot_integration_test.dart index 4bf2252685..cedf8bca43 100644 --- a/flutter/test/integrations/screenshot_integration_test.dart +++ b/flutter/test/integrations/screenshot_integration_test.dart @@ -1,8 +1,8 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/event_processor/screenshot_event_processor.dart'; import 'package:sentry_flutter/src/integrations/screenshot_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -69,7 +69,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); ScreenshotIntegration getSut({bool attachScreenshot = true}) { options.attachScreenshot = attachScreenshot; diff --git a/flutter/test/integrations/widgets_flutter_binding_integration_test.dart b/flutter/test/integrations/widgets_flutter_binding_integration_test.dart index 72fb406ee9..3ab2a8f89c 100644 --- a/flutter/test/integrations/widgets_flutter_binding_integration_test.dart +++ b/flutter/test/integrations/widgets_flutter_binding_integration_test.dart @@ -1,6 +1,5 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/integrations/widgets_flutter_binding_integration.dart'; import '../mocks.dart'; @@ -43,8 +42,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(dsn: fakeDsn) - ..bindingUtils = TestBindingWrapper(); + final options = defaultTestOptions()..bindingUtils = TestBindingWrapper(); TestBindingWrapper get testBindingUtils => options.bindingUtils as TestBindingWrapper; diff --git a/flutter/test/mocks.dart b/flutter/test/mocks.dart index ee74889877..b920578f0f 100644 --- a/flutter/test/mocks.dart +++ b/flutter/test/mocks.dart @@ -4,6 +4,7 @@ import 'package:flutter/services.dart'; import 'package:flutter/src/widgets/binding.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; import 'package:sentry/src/platform/platform.dart'; import 'package:sentry/src/sentry_tracer.dart'; @@ -18,10 +19,9 @@ import 'no_such_method_provider.dart'; const fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; const fakeProguardUuid = '3457d982-65ef-576d-a6ad-65b5f30f49a5'; -// TODO use this everywhere in tests so that we don't get exceptions swallowed. -SentryFlutterOptions defaultTestOptions() { - // ignore: invalid_use_of_internal_member - return SentryFlutterOptions(dsn: fakeDsn)..automatedTestMode = true; +SentryFlutterOptions defaultTestOptions([PlatformChecker? checker]) { + return SentryFlutterOptions(dsn: fakeDsn, checker: checker) + ..automatedTestMode = true; } // https://github.com/dart-lang/mockito/blob/master/NULL_SAFETY_README.md#fallback-generators @@ -46,6 +46,7 @@ ISentrySpan startTransactionShim( SentryTracer, SentryTransaction, SentrySpan, + SentryClient, MethodChannel, SentryNativeBinding ], customMocks: [ @@ -168,8 +169,6 @@ class TestBindingWrapper implements BindingWrapper { } } -class MockSentryClient with NoSuchMethodProvider implements SentryClient {} - // All these values are based on the fakeFrameDurations list. // The expected total frames is also based on the span duration of 1000ms and the slow and frozen frames. const expectedTotalFrames = 17; @@ -201,6 +200,8 @@ class NativeChannelFixture { TestWidgetsFlutterBinding.ensureInitialized(); channel = MethodChannel('test.channel', StandardMethodCodec(), _messenger); handler = MockCallbacks().methodCallHandler; + when(handler('initNativeSdk', any)).thenAnswer((_) => Future.value()); + when(handler('closeNativeSdk', any)).thenAnswer((_) => Future.value()); _messenger.setMockMethodCallHandler( channel, (call) => handler(call.method, call.arguments)); } @@ -213,3 +214,17 @@ class NativeChannelFixture { channel.name, call, (ByteData? data) {}); } } + +typedef EventProcessorFunction = SentryEvent? Function( + SentryEvent event, Hint hint); + +class FunctionEventProcessor implements EventProcessor { + FunctionEventProcessor(this.applyFunction); + + final EventProcessorFunction applyFunction; + + @override + SentryEvent? apply(SentryEvent event, Hint hint) { + return applyFunction(event, hint); + } +} diff --git a/flutter/test/mocks.mocks.dart b/flutter/test/mocks.mocks.dart index feb97b5927..3f94ca0274 100644 --- a/flutter/test/mocks.mocks.dart +++ b/flutter/test/mocks.mocks.dart @@ -4,19 +4,19 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i7; -import 'dart:typed_data' as _i12; +import 'dart:typed_data' as _i13; import 'package:flutter/services.dart' as _i4; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i8; -import 'package:sentry/src/metrics/metric.dart' as _i14; +import 'package:sentry/src/metrics/metric.dart' as _i10; import 'package:sentry/src/metrics/metrics_api.dart' as _i5; import 'package:sentry/src/profiling.dart' as _i9; import 'package:sentry/src/sentry_tracer.dart' as _i3; import 'package:sentry_flutter/sentry_flutter.dart' as _i2; -import 'package:sentry_flutter/src/native/native_app_start.dart' as _i11; -import 'package:sentry_flutter/src/native/native_frames.dart' as _i13; -import 'package:sentry_flutter/src/native/sentry_native_binding.dart' as _i10; +import 'package:sentry_flutter/src/native/native_app_start.dart' as _i12; +import 'package:sentry_flutter/src/native/native_frames.dart' as _i14; +import 'package:sentry_flutter/src/native/sentry_native_binding.dart' as _i11; import 'mocks.dart' as _i6; @@ -280,6 +280,12 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValueForMissingStub: null, ); + @override + Map get measurements => (super.noSuchMethod( + Invocation.getter(#measurements), + returnValue: {}, + ) as Map); + @override _i2.SentrySpanContext get context => (super.noSuchMethod( Invocation.getter(#context), @@ -349,12 +355,6 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValue: {}, ) as Map); - @override - Map get measurements => (super.noSuchMethod( - Invocation.getter(#measurements), - returnValue: {}, - ) as Map); - @override _i7.Future finish({ _i2.SpanStatus? status, @@ -519,6 +519,24 @@ class MockSentryTracer extends _i1.Mock implements _i3.SentryTracer { returnValueForMissingStub: null, ); + @override + void setMeasurementFromChild( + String? name, + num? value, { + _i2.SentryMeasurementUnit? unit, + }) => + super.noSuchMethod( + Invocation.method( + #setMeasurementFromChild, + [ + name, + value, + ], + {#unit: unit}, + ), + returnValueForMissingStub: null, + ); + @override void scheduleFinish() => super.noSuchMethod( Invocation.method( @@ -998,6 +1016,189 @@ class MockSentrySpan extends _i1.Mock implements _i2.SentrySpan { ); } +/// A class which mocks [SentryClient]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockSentryClient extends _i1.Mock implements _i2.SentryClient { + MockSentryClient() { + _i1.throwOnMissingStub(this); + } + + @override + _i7.Future<_i2.SentryId> captureEvent( + _i2.SentryEvent? event, { + _i2.Scope? scope, + dynamic stackTrace, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureEvent, + [event], + { + #scope: scope, + #stackTrace: stackTrace, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureEvent, + [event], + { + #scope: scope, + #stackTrace: stackTrace, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureException( + dynamic throwable, { + dynamic stackTrace, + _i2.Scope? scope, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #scope: scope, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureException, + [throwable], + { + #stackTrace: stackTrace, + #scope: scope, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureMessage( + String? formatted, { + _i2.SentryLevel? level, + String? template, + List? params, + _i2.Scope? scope, + _i2.Hint? hint, + }) => + (super.noSuchMethod( + Invocation.method( + #captureMessage, + [formatted], + { + #level: level, + #template: template, + #params: params, + #scope: scope, + #hint: hint, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureMessage, + [formatted], + { + #level: level, + #template: template, + #params: params, + #scope: scope, + #hint: hint, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId> captureTransaction( + _i2.SentryTransaction? transaction, { + _i2.Scope? scope, + _i2.SentryTraceContextHeader? traceContext, + }) => + (super.noSuchMethod( + Invocation.method( + #captureTransaction, + [transaction], + { + #scope: scope, + #traceContext: traceContext, + }, + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureTransaction, + [transaction], + { + #scope: scope, + #traceContext: traceContext, + }, + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + _i7.Future<_i2.SentryId?> captureEnvelope(_i2.SentryEnvelope? envelope) => + (super.noSuchMethod( + Invocation.method( + #captureEnvelope, + [envelope], + ), + returnValue: _i7.Future<_i2.SentryId?>.value(), + ) as _i7.Future<_i2.SentryId?>); + + @override + _i7.Future captureUserFeedback(_i2.SentryUserFeedback? userFeedback) => + (super.noSuchMethod( + Invocation.method( + #captureUserFeedback, + [userFeedback], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + + @override + _i7.Future<_i2.SentryId> captureMetrics( + Map>? metricsBuckets) => + (super.noSuchMethod( + Invocation.method( + #captureMetrics, + [metricsBuckets], + ), + returnValue: _i7.Future<_i2.SentryId>.value(_FakeSentryId_5( + this, + Invocation.method( + #captureMetrics, + [metricsBuckets], + ), + )), + ) as _i7.Future<_i2.SentryId>); + + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + /// A class which mocks [MethodChannel]. /// /// See the documentation for Mockito's code generation for more information. @@ -1097,7 +1298,7 @@ class MockMethodChannel extends _i1.Mock implements _i4.MethodChannel { /// /// See the documentation for Mockito's code generation for more information. class MockSentryNativeBinding extends _i1.Mock - implements _i10.SentryNativeBinding { + implements _i11.SentryNativeBinding { MockSentryNativeBinding() { _i1.throwOnMissingStub(this); } @@ -1123,17 +1324,17 @@ class MockSentryNativeBinding extends _i1.Mock ) as _i7.Future); @override - _i7.Future<_i11.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( + _i7.Future<_i12.NativeAppStart?> fetchNativeAppStart() => (super.noSuchMethod( Invocation.method( #fetchNativeAppStart, [], ), - returnValue: _i7.Future<_i11.NativeAppStart?>.value(), - ) as _i7.Future<_i11.NativeAppStart?>); + returnValue: _i7.Future<_i12.NativeAppStart?>.value(), + ) as _i7.Future<_i12.NativeAppStart?>); @override _i7.Future captureEnvelope( - _i12.Uint8List? envelopeData, + _i13.Uint8List? envelopeData, bool? containsUnhandledException, ) => (super.noSuchMethod( @@ -1159,14 +1360,14 @@ class MockSentryNativeBinding extends _i1.Mock ) as _i7.Future); @override - _i7.Future<_i13.NativeFrames?> endNativeFrames(_i2.SentryId? id) => + _i7.Future<_i14.NativeFrames?> endNativeFrames(_i2.SentryId? id) => (super.noSuchMethod( Invocation.method( #endNativeFrames, [id], ), - returnValue: _i7.Future<_i13.NativeFrames?>.value(), - ) as _i7.Future<_i13.NativeFrames?>); + returnValue: _i7.Future<_i14.NativeFrames?>.value(), + ) as _i7.Future<_i14.NativeFrames?>); @override _i7.Future setUser(_i2.SentryUser? user) => (super.noSuchMethod( @@ -1363,6 +1564,16 @@ class MockSentryNativeBinding extends _i1.Mock returnValueForMissingStub: _i7.Future.value(), ) as _i7.Future); + @override + _i7.Future nativeCrash() => (super.noSuchMethod( + Invocation.method( + #nativeCrash, + [], + ), + returnValue: _i7.Future.value(), + returnValueForMissingStub: _i7.Future.value(), + ) as _i7.Future); + @override _i7.Future<_i2.SentryId> captureReplay(bool? isCrash) => (super.noSuchMethod( Invocation.method( @@ -1715,7 +1926,7 @@ class MockHub extends _i1.Mock implements _i2.Hub { @override _i7.Future<_i2.SentryId> captureMetrics( - Map>? metricsBuckets) => + Map>? metricsBuckets) => (super.noSuchMethod( Invocation.method( #captureMetrics, diff --git a/flutter/test/navigation/sentry_display_widget_test.dart b/flutter/test/navigation/sentry_display_widget_test.dart index a0495bfe8d..abbd6e70dc 100644 --- a/flutter/test/navigation/sentry_display_widget_test.dart +++ b/flutter/test/navigation/sentry_display_widget_test.dart @@ -102,8 +102,7 @@ void main() { } class Fixture { - final Hub hub = - Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final Hub hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); late final SentryNavigatorObserver navigatorObserver; final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); diff --git a/flutter/test/navigation/time_to_display_tracker_test.dart b/flutter/test/navigation/time_to_display_tracker_test.dart index 975adb37fd..6e074bac6e 100644 --- a/flutter/test/navigation/time_to_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_display_tracker_test.dart @@ -255,7 +255,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final options = SentryFlutterOptions() + final options = defaultTestOptions() ..dsn = fakeDsn ..tracesSampleRate = 1.0; late final endTimeProvider = ttidEndTimestampProvider(); diff --git a/flutter/test/navigation/time_to_full_display_tracker_test.dart b/flutter/test/navigation/time_to_full_display_tracker_test.dart index 50609f2692..95d5a3ee25 100644 --- a/flutter/test/navigation/time_to_full_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_full_display_tracker_test.dart @@ -65,7 +65,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final hub = Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); final autoFinishAfter = const Duration(seconds: 2); late final endTimestampProvider = fakeTTIDEndTimestampProvider(); diff --git a/flutter/test/navigation/time_to_initial_display_tracker_test.dart b/flutter/test/navigation/time_to_initial_display_tracker_test.dart index 6e55029572..1f85360f55 100644 --- a/flutter/test/navigation/time_to_initial_display_tracker_test.dart +++ b/flutter/test/navigation/time_to_initial_display_tracker_test.dart @@ -179,7 +179,7 @@ void main() { class Fixture { final startTimestamp = getUtcDateTime(); - final hub = Hub(SentryFlutterOptions(dsn: fakeDsn)..tracesSampleRate = 1.0); + final hub = Hub(defaultTestOptions()..tracesSampleRate = 1.0); late final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); ISentrySpan getTransaction({String? name = "Regular route"}) { diff --git a/flutter/test/profiling_test.dart b/flutter/test/profiling_test.dart index 04ff70d065..5ab944e53f 100644 --- a/flutter/test/profiling_test.dart +++ b/flutter/test/profiling_test.dart @@ -19,7 +19,7 @@ void main() { group('$SentryNativeProfilerFactory', () { Hub hubWithSampleRate(double profilesSampleRate) { - final o = SentryFlutterOptions(dsn: fakeDsn); + final o = defaultTestOptions(); o.platformChecker = getPlatformChecker(platform: MockPlatform.iOs()); o.profilesSampleRate = profilesSampleRate; diff --git a/flutter/test/replay/recorder_test.dart b/flutter/test/replay/recorder_test.dart index 16db1513b5..2df4334c5b 100644 --- a/flutter/test/replay/recorder_test.dart +++ b/flutter/test/replay/recorder_test.dart @@ -6,7 +6,6 @@ library dart_test; import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/replay/recorder.dart'; import 'package:sentry_flutter/src/replay/recorder_config.dart'; @@ -28,7 +27,7 @@ class _Fixture { _Fixture._() { sut = ScreenshotRecorder( ScreenshotRecorderConfig(), - SentryFlutterOptions()..bindingUtils = TestBindingWrapper(), + defaultTestOptions()..bindingUtils = TestBindingWrapper(), ); } diff --git a/flutter/test/replay/replay_native_test.dart b/flutter/test/replay/replay_native_test.dart index e9b047d8b0..c758cd3005 100644 --- a/flutter/test/replay/replay_native_test.dart +++ b/flutter/test/replay/replay_native_test.dart @@ -57,17 +57,14 @@ void main() { replayDir = fs.directory(replayConfig['directory']) ..createSync(recursive: true); - options = defaultTestOptions() - ..platformChecker = MockPlatformChecker(mockPlatform: mockPlatform) - ..fileSystem = fs; - native = NativeChannelFixture(); - when(native.handler('initNativeSdk', any)) - .thenAnswer((_) => Future.value()); - when(native.handler('closeNativeSdk', any)) - .thenAnswer((_) => Future.value()); - sut = createBinding(options, channel: native.channel); + options = + defaultTestOptions(MockPlatformChecker(mockPlatform: mockPlatform)) + ..fileSystem = fs + ..methodChannel = native.channel; + + sut = createBinding(options); }); tearDown(() async { diff --git a/flutter/test/replay/scheduled_recorder_test.dart b/flutter/test/replay/scheduled_recorder_test.dart index f859b27d53..7ace54c18e 100644 --- a/flutter/test/replay/scheduled_recorder_test.dart +++ b/flutter/test/replay/scheduled_recorder_test.dart @@ -6,7 +6,6 @@ library dart_test; import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/replay/scheduled_recorder.dart'; import 'package:sentry_flutter/src/replay/recorder_config.dart'; @@ -45,7 +44,7 @@ class _Fixture { (Image image) async { capturedImages.add("${image.width}x${image.height}"); }, - SentryFlutterOptions()..bindingUtils = TestBindingWrapper(), + defaultTestOptions()..bindingUtils = TestBindingWrapper(), ); } diff --git a/flutter/test/screenshot/sentry_screenshot_widget_test.dart b/flutter/test/screenshot/sentry_screenshot_widget_test.dart index 0b6df7ffad..bedbfe8f1f 100644 --- a/flutter/test/screenshot/sentry_screenshot_widget_test.dart +++ b/flutter/test/screenshot/sentry_screenshot_widget_test.dart @@ -53,7 +53,7 @@ void main() { } class Fixture { - final _options = SentryFlutterOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub hub; SentryScreenshotWidget getSut({ diff --git a/flutter/test/sentry_asset_bundle_test.dart b/flutter/test/sentry_asset_bundle_test.dart index c5236f674a..cd17f3e279 100644 --- a/flutter/test/sentry_asset_bundle_test.dart +++ b/flutter/test/sentry_asset_bundle_test.dart @@ -516,7 +516,7 @@ void main() { } class Fixture { - final _options = SentryOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); late Hub _hub; final transport = MockTransport(); final assetBundle = TestAssetBundle(); diff --git a/flutter/test/sentry_flutter_options_test.dart b/flutter/test/sentry_flutter_options_test.dart index ed4a3ea7f7..7c4d2e79b1 100644 --- a/flutter/test/sentry_flutter_options_test.dart +++ b/flutter/test/sentry_flutter_options_test.dart @@ -1,6 +1,4 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import 'mocks.dart'; @@ -8,8 +6,8 @@ void main() { group('SentryFlutterOptions', () { testWidgets('auto breadcrumb tracking: has native integration', (WidgetTester tester) async { - final options = SentryFlutterOptions( - checker: MockPlatformChecker(hasNativeIntegration: true)); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: true)); expect(options.enableAppLifecycleBreadcrumbs, isFalse); expect(options.enableWindowMetricBreadcrumbs, isFalse); @@ -21,8 +19,8 @@ void main() { testWidgets('auto breadcrumb tracking: without native integration', (WidgetTester tester) async { - final options = SentryFlutterOptions( - checker: MockPlatformChecker(hasNativeIntegration: false)); + final options = + defaultTestOptions(MockPlatformChecker(hasNativeIntegration: false)); expect(options.enableAppLifecycleBreadcrumbs, isTrue); expect(options.enableWindowMetricBreadcrumbs, isTrue); @@ -33,7 +31,7 @@ void main() { }); testWidgets('useNativeBreadcrumbTracking', (WidgetTester tester) async { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); options.useNativeBreadcrumbTracking(); expect(options.enableAppLifecycleBreadcrumbs, isFalse); @@ -45,7 +43,7 @@ void main() { }); testWidgets('useFlutterBreadcrumbTracking', (WidgetTester tester) async { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); options.useFlutterBreadcrumbTracking(); expect(options.enableAppLifecycleBreadcrumbs, isTrue); diff --git a/flutter/test/sentry_flutter_test.dart b/flutter/test/sentry_flutter_test.dart index 534dd6ac1e..7cd3794285 100644 --- a/flutter/test/sentry_flutter_test.dart +++ b/flutter/test/sentry_flutter_test.dart @@ -55,6 +55,11 @@ final nativeIntegrations = [ void main() { TestWidgetsFlutterBinding.ensureInitialized(); + late NativeChannelFixture native; + + setUp(() async { + native = NativeChannelFixture(); + }); group('Test platform integrations', () { setUp(() async { @@ -67,19 +72,19 @@ void main() { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker(platform: MockPlatform.android()), + options: sentryFlutterOptions, ); testTransport( @@ -88,7 +93,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, expectedHasNativeScopeObserver: true); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: true); testConfiguration( integrations: integrations, @@ -121,19 +126,20 @@ void main() { test('iOS', () async { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.iOs())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker(platform: MockPlatform.iOs()), + options: sentryFlutterOptions, ); testTransport( @@ -142,7 +148,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, expectedHasNativeScopeObserver: true); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: true); testConfiguration( integrations: integrations, @@ -173,19 +179,19 @@ void main() { test('macOS', () async { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.macOs())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker(platform: MockPlatform.macOs()), + options: sentryFlutterOptions, ); testTransport( @@ -194,7 +200,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, expectedHasNativeScopeObserver: true); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: true); testConfiguration(integrations: integrations, shouldHaveIntegrations: [ ...iOsAndMacOsIntegrations, @@ -221,19 +227,19 @@ void main() { test('Windows', () async { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.windows())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker(platform: MockPlatform.windows()), + options: sentryFlutterOptions, ); testTransport( @@ -242,8 +248,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, - expectedHasNativeScopeObserver: false); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: false); testConfiguration( integrations: integrations, @@ -273,19 +278,19 @@ void main() { test('Linux', () async { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + final sentryFlutterOptions = + defaultTestOptions(getPlatformChecker(platform: MockPlatform.linux())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker(platform: MockPlatform.linux()), + options: sentryFlutterOptions, ); testTransport( @@ -294,8 +299,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, - expectedHasNativeScopeObserver: false); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: false); testConfiguration( integrations: integrations, @@ -325,22 +329,18 @@ void main() { test('Web', () async { List integrations = []; Transport transport = MockTransport(); - SentryFlutterOptions? sentryFlutterOptions; + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.linux())) + ..methodChannel = native.channel; await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; options.profilesSampleRate = 1.0; integrations = options.integrations; transport = options.transport; - sentryFlutterOptions = options; }, appRunner: appRunner, - platformChecker: getPlatformChecker( - isWeb: true, - platform: MockPlatform.linux(), - ), + options: sentryFlutterOptions, ); testTransport( @@ -349,8 +349,7 @@ void main() { ); testScopeObserver( - options: sentryFlutterOptions!, - expectedHasNativeScopeObserver: false); + options: sentryFlutterOptions, expectedHasNativeScopeObserver: false); testConfiguration( integrations: integrations, @@ -380,21 +379,19 @@ void main() { test('Web && (iOS || macOS)', () async { List integrations = []; Transport transport = MockTransport(); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.iOs())) + ..methodChannel = native.channel; // Tests that iOS || macOS integrations aren't added on a browser which // runs on iOS or macOS await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, appRunner: appRunner, - platformChecker: getPlatformChecker( - isWeb: true, - platform: MockPlatform.iOs(), - ), + options: sentryFlutterOptions, ); testTransport( @@ -427,21 +424,19 @@ void main() { test('Web && (macOS)', () async { List integrations = []; Transport transport = MockTransport(); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.macOs())) + ..methodChannel = native.channel; // Tests that iOS || macOS integrations aren't added on a browser which // runs on iOS or macOS await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, appRunner: appRunner, - platformChecker: getPlatformChecker( - isWeb: true, - platform: MockPlatform.macOs(), - ), + options: sentryFlutterOptions, ); testTransport( @@ -476,20 +471,18 @@ void main() { test('Web && Android', () async { List integrations = []; Transport transport = MockTransport(); + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(isWeb: true, platform: MockPlatform.android())) + ..methodChannel = native.channel; // Tests that Android integrations aren't added on an Android browser await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; transport = options.transport; }, appRunner: appRunner, - platformChecker: getPlatformChecker( - isWeb: true, - platform: MockPlatform.android(), - ), + options: sentryFlutterOptions, ); testTransport( @@ -528,16 +521,19 @@ void main() { test('installed on io platforms', () async { List integrations = []; + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.iOs(), isWeb: false)) + ..methodChannel = native.channel + ..rendererWrapper = MockRendererWrapper(FlutterRenderer.skia) + ..release = '' + ..dist = ''; + await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, - platformChecker: - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: false), - rendererWrapper: MockRendererWrapper(FlutterRenderer.skia), + options: sentryFlutterOptions, ); expect( @@ -552,16 +548,18 @@ 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 = ''; + await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, - platformChecker: - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true), - rendererWrapper: MockRendererWrapper(FlutterRenderer.canvasKit), + options: sentryFlutterOptions, ); expect( @@ -576,16 +574,18 @@ void main() { test('not installed with html renderer', () async { List integrations = []; + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true)) + ..rendererWrapper = MockRendererWrapper(FlutterRenderer.html) + ..release = '' + ..dist = ''; + await SentryFlutter.init( (options) async { - options.dsn = fakeDsn; - options.automatedTestMode = true; integrations = options.integrations; }, appRunner: appRunner, - platformChecker: - getPlatformChecker(platform: MockPlatform.iOs(), isWeb: true), - rendererWrapper: MockRendererWrapper(FlutterRenderer.html), + options: sentryFlutterOptions, ); expect( @@ -605,11 +605,11 @@ void main() { }); test('test that initial values are set correctly', () async { + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); + await SentryFlutter.init( (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; - expect(false, options.debug); expect('debug', options.environment); expect(sdkName, options.sdk.name); @@ -618,10 +618,7 @@ void main() { expect(sdkVersion, options.sdk.packages.last.version); }, appRunner: appRunner, - platformChecker: getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ), + options: sentryFlutterOptions, ); await Sentry.close(); @@ -630,19 +627,15 @@ void main() { test( 'enablePureDartSymbolication is set to false during SentryFlutter init', () async { + final sentryFlutterOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); SentryFlutter.native = MockSentryNativeBinding(); await SentryFlutter.init( (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; - expect(options.enableDartSymbolication, false); }, appRunner: appRunner, - platformChecker: getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ), + options: sentryFlutterOptions, ); await Sentry.close(); @@ -696,24 +689,18 @@ void main() { test( 'should add DartExceptionTypeIdentifier and FlutterExceptionTypeIdentifier by default', () async { - SentryOptions? actualOptions; + final actualOptions = defaultTestOptions( + getPlatformChecker(platform: MockPlatform.android(), isWeb: true)); await SentryFlutter.init( - (options) { - options.dsn = fakeDsn; - options.automatedTestMode = true; - actualOptions = options; - }, + (options) {}, appRunner: appRunner, - platformChecker: getPlatformChecker( - platform: MockPlatform.android(), - isWeb: true, - ), + options: actualOptions, ); - expect(actualOptions!.exceptionTypeIdentifiers.length, 2); + expect(actualOptions.exceptionTypeIdentifiers.length, 2); // Flutter identifier should be first as it's more specific expect( - actualOptions!.exceptionTypeIdentifiers.first, + actualOptions.exceptionTypeIdentifiers.first, isA().having( (c) => c.identifier, 'wrapped identifier', @@ -721,7 +708,7 @@ void main() { ), ); expect( - actualOptions!.exceptionTypeIdentifiers[1], + actualOptions.exceptionTypeIdentifiers[1], isA().having( (c) => c.identifier, 'wrapped identifier', diff --git a/flutter/test/sentry_native_channel_test.dart b/flutter/test/sentry_native_channel_test.dart index fb339b4682..0428349d49 100644 --- a/flutter/test/sentry_native_channel_test.dart +++ b/flutter/test/sentry_native_channel_test.dart @@ -27,12 +27,11 @@ void main() { late MockMethodChannel channel; setUp(() { - final options = SentryFlutterOptions( - dsn: fakeDsn, checker: getPlatformChecker(platform: mockPlatform)) - // ignore: invalid_use_of_internal_member - ..automatedTestMode = true; channel = MockMethodChannel(); - sut = createBinding(options, channel: channel); + final options = + defaultTestOptions(getPlatformChecker(platform: mockPlatform)) + ..methodChannel = channel; + sut = createBinding(options); }); // TODO move other methods here, e.g. init_native_sdk_test.dart diff --git a/flutter/test/sentry_navigator_observer_test.dart b/flutter/test/sentry_navigator_observer_test.dart index 9a64d65414..524f3e2ece 100644 --- a/flutter/test/sentry_navigator_observer_test.dart +++ b/flutter/test/sentry_navigator_observer_test.dart @@ -83,6 +83,8 @@ void main() { final options = defaultTestOptions(); options.tracesSampleRate = 1; + // Drop events, otherwise sentry tries to send them to the test DSN. + options.addEventProcessor(FunctionEventProcessor((_, __) => null)); final hub = Hub(options); when(mockBinding.endNativeFrames(any)) @@ -598,6 +600,7 @@ void main() { const op = 'navigation'; final hub = _MockHub(); final span = getMockSentryTracer(name: oldRouteName); + when(span.children).thenReturn([]); when(span.context).thenReturn(SentrySpanContext(operation: op)); when(span.status).thenReturn(null); when(span.finished).thenReturn(false); @@ -982,6 +985,7 @@ void main() { final secondRoute = route(RouteSettings(name: 'testRoute')); final hub = _MockHub(); + _whenAnyStart(hub, NoOpSentrySpan()); final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]); @@ -1002,6 +1006,7 @@ void main() { final secondRoute = route(RouteSettings(name: 'testRoute')); final hub = _MockHub(); + _whenAnyStart(hub, NoOpSentrySpan()); final sut = fixture.getSut(hub: hub, ignoreRoutes: ["testRoute"]); @@ -1086,7 +1091,7 @@ class _MockHub extends MockHub { } } -ISentrySpan getMockSentryTracer({String? name, bool? finished}) { +MockSentryTracer getMockSentryTracer({String? name, bool? finished}) { final tracer = MockSentryTracer(); when(tracer.name).thenReturn(name ?? 'name'); when(tracer.finished).thenReturn(finished ?? true); diff --git a/flutter/test/span_frame_metrics_collector_test.dart b/flutter/test/span_frame_metrics_collector_test.dart index 70c3348070..41cb56b6d5 100644 --- a/flutter/test/span_frame_metrics_collector_test.dart +++ b/flutter/test/span_frame_metrics_collector_test.dart @@ -262,7 +262,7 @@ void main() { } class Fixture { - final options = SentryFlutterOptions(dsn: fakeDsn); + final options = defaultTestOptions(); late final hub = Hub(options); final fakeFrameCallbackHandler = FakeFrameCallbackHandler(); final mockSentryNative = MockSentryNativeBinding(); diff --git a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart index b0288729b2..cdb27f9275 100644 --- a/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart +++ b/flutter/test/user_interaction/sentry_user_interaction_widget_test.dart @@ -524,7 +524,7 @@ Future tapMe( } class Fixture { - final _options = SentryFlutterOptions(dsn: fakeDsn); + final _options = defaultTestOptions(); final _transport = MockTransport(); late Hub hub; diff --git a/flutter/test/view_hierarchy/sentry_tree_walker_test.dart b/flutter/test/view_hierarchy/sentry_tree_walker_test.dart index 9fd41fc522..26a7c41a0a 100644 --- a/flutter/test/view_hierarchy/sentry_tree_walker_test.dart +++ b/flutter/test/view_hierarchy/sentry_tree_walker_test.dart @@ -3,6 +3,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/view_hierarchy/sentry_tree_walker.dart'; +import '../mocks.dart'; + void main() { group('TreeWalker', () { late WidgetsBinding instance; @@ -17,7 +19,7 @@ void main() { await tester.pumpWidget(MyApp()); final sentryViewHierarchy = - walkWidgetTree(instance, SentryFlutterOptions()); + walkWidgetTree(instance, defaultTestOptions()); expect(sentryViewHierarchy!.renderingSystem, 'flutter'); }); @@ -148,7 +150,7 @@ void main() { SentryViewHierarchyElement _getFirstSentryViewHierarchy( WidgetsBinding instance) { - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); final sentryViewHierarchy = walkWidgetTree(instance, options); return sentryViewHierarchy!.windows.first; diff --git a/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart b/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart index 98487ab3a2..9ba8a694ff 100644 --- a/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart +++ b/flutter/test/view_hierarchy/view_hierarchy_event_processor_test.dart @@ -4,9 +4,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:sentry/sentry.dart'; import 'package:sentry_flutter/src/binding_wrapper.dart'; -import 'package:sentry_flutter/src/sentry_flutter_options.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_event_processor.dart'; +import '../mocks.dart'; + void main() { group(SentryViewHierarchyEventProcessor, () { late Fixture fixture; @@ -124,7 +125,7 @@ class TestBindingWrapper implements BindingWrapper { class Fixture { SentryViewHierarchyEventProcessor getSut(WidgetsBinding instance, {bool reportViewHierarchyIdentifiers = true}) { - final options = SentryFlutterOptions() + final options = defaultTestOptions() ..bindingUtils = TestBindingWrapper(instance) ..reportViewHierarchyIdentifiers = reportViewHierarchyIdentifiers; return SentryViewHierarchyEventProcessor(options); diff --git a/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart b/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart index bef4050c6e..c57fff8b5e 100644 --- a/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart +++ b/flutter/test/view_hierarchy/view_hierarchy_integration_test.dart @@ -2,10 +2,10 @@ library flutter_test; import 'package:flutter_test/flutter_test.dart'; -import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_event_processor.dart'; import 'package:sentry_flutter/src/view_hierarchy/view_hierarchy_integration.dart'; +import '../mocks.dart'; import '../mocks.mocks.dart'; void main() { @@ -74,7 +74,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryFlutterOptions(); + final options = defaultTestOptions(); SentryViewHierarchyIntegration getSut({bool attachViewHierarchy = true}) { options.attachViewHierarchy = attachViewHierarchy; diff --git a/flutter/test/widgets_binding_observer_test.dart b/flutter/test/widgets_binding_observer_test.dart index 86973ba91c..ce44577db9 100644 --- a/flutter/test/widgets_binding_observer_test.dart +++ b/flutter/test/widgets_binding_observer_test.dart @@ -17,11 +17,11 @@ void main() { setUp(() { TestWidgetsFlutterBinding.ensureInitialized(); - flutterTrackingEnabledOptions = SentryFlutterOptions() + flutterTrackingEnabledOptions = defaultTestOptions() ..bindingUtils = TestBindingWrapper(); flutterTrackingEnabledOptions.useFlutterBreadcrumbTracking(); - flutterTrackingDisabledOptions = SentryFlutterOptions() + flutterTrackingDisabledOptions = defaultTestOptions() ..bindingUtils = TestBindingWrapper(); flutterTrackingDisabledOptions.useNativeBreadcrumbTracking(); }); diff --git a/hive/test/sentry_box_base_test.dart b/hive/test/sentry_box_base_test.dart index 3821b8b341..e46564a3f3 100644 --- a/hive/test/sentry_box_base_test.dart +++ b/hive/test/sentry_box_base_test.dart @@ -12,6 +12,7 @@ import 'package:sentry/src/sentry_tracer.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -525,7 +526,7 @@ void main() { class Fixture { late final Box box; late final mockBox = MockBox(); - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/sentry_box_collection_test.dart b/hive/test/sentry_box_collection_test.dart index f13b95e1c8..3f730be3c1 100644 --- a/hive/test/sentry_box_collection_test.dart +++ b/hive/test/sentry_box_collection_test.dart @@ -15,6 +15,8 @@ import 'person.dart'; import 'package:hive/src/box_collection/box_collection_stub.dart' as stub; +import 'utils.dart'; + void main() { void verifySpan(String description, SentrySpan? span) { expect(span?.context.operation, SentryHiveImpl.dbOp); @@ -355,7 +357,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/sentry_hive_impl_test.dart b/hive/test/sentry_hive_impl_test.dart index 521415d1ed..a478c9f24a 100644 --- a/hive/test/sentry_hive_impl_test.dart +++ b/hive/test/sentry_hive_impl_test.dart @@ -14,6 +14,7 @@ import 'package:test/test.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan( @@ -583,7 +584,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); late final mockHive = MockHiveInterface(); final hub = MockHub(); static final dbName = 'people-hive-impl'; diff --git a/hive/test/sentry_lazy_box_test.dart b/hive/test/sentry_lazy_box_test.dart index 291dc3fc20..72282ada42 100644 --- a/hive/test/sentry_lazy_box_test.dart +++ b/hive/test/sentry_lazy_box_test.dart @@ -12,6 +12,7 @@ import 'package:test/test.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -247,7 +248,7 @@ void main() { class Fixture { late final LazyBox box; late final mockBox = MockLazyBox(); - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final exception = Exception('fixture-exception'); diff --git a/hive/test/utils.dart b/hive/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/hive/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/isar/test/sentry_isar_collection_test.dart b/isar/test/sentry_isar_collection_test.dart index de55ac5989..5cf06586ea 100644 --- a/isar/test/sentry_isar_collection_test.dart +++ b/isar/test/sentry_isar_collection_test.dart @@ -12,6 +12,7 @@ import 'package:sentry/src/sentry_tracer.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan( @@ -876,7 +877,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final isarCollection = MockIsarCollection(); diff --git a/isar/test/sentry_isar_test.dart b/isar/test/sentry_isar_test.dart index 222226fa53..00bafb2164 100644 --- a/isar/test/sentry_isar_test.dart +++ b/isar/test/sentry_isar_test.dart @@ -13,6 +13,7 @@ import 'package:sentry_isar/src/version.dart'; import 'mocks/mocks.mocks.dart'; import 'person.dart'; +import 'utils.dart'; void main() { void verifySpan(String description, SentrySpan? span) { @@ -416,7 +417,7 @@ void main() { } class Fixture { - final options = SentryOptions(); + final options = defaultTestOptions(); final hub = MockHub(); final isar = MockIsar(); diff --git a/isar/test/utils.dart b/isar/test/utils.dart new file mode 100644 index 0000000000..7fb87861f0 --- /dev/null +++ b/isar/test/utils.dart @@ -0,0 +1,8 @@ +import 'package:sentry/sentry.dart'; + +final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} diff --git a/logging/test/logging_integration_test.dart b/logging/test/logging_integration_test.dart index 5ddb50cf3e..c5e78657a5 100644 --- a/logging/test/logging_integration_test.dart +++ b/logging/test/logging_integration_test.dart @@ -203,7 +203,7 @@ void main() { } class Fixture { - SentryOptions options = SentryOptions(dsn: fakeDsn); + SentryOptions options = defaultTestOptions(); MockHub hub = MockHub(); LoggingIntegration createSut({ diff --git a/logging/test/mock_hub.dart b/logging/test/mock_hub.dart index 3dcb1d4fc8..ec3d8b2af9 100644 --- a/logging/test/mock_hub.dart +++ b/logging/test/mock_hub.dart @@ -6,10 +6,15 @@ import 'no_such_method_provider.dart'; final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +} + class MockHub with NoSuchMethodProvider implements Hub { final List breadcrumbs = []; final List events = []; - final _options = SentryOptions(dsn: 'fixture-dsn'); + final _options = defaultTestOptions(); @override @internal diff --git a/metrics/flutter.properties b/metrics/flutter.properties index 70b1f7cd48..9a86225f5e 100644 --- a/metrics/flutter.properties +++ b/metrics/flutter.properties @@ -1,2 +1,2 @@ -version = 3.24.2 +version = 3.24.3 repo = https://github.com/flutter/flutter diff --git a/sqflite/test/sentry_batch_test.dart b/sqflite/test/sentry_batch_test.dart index 4a5062f2a2..50dc469ab3 100644 --- a/sqflite/test/sentry_batch_test.dart +++ b/sqflite/test/sentry_batch_test.dart @@ -668,7 +668,7 @@ SELECT * FROM Product'''; class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); final batch = MockBatch(); diff --git a/sqflite/test/sentry_database_test.dart b/sqflite/test/sentry_database_test.dart index 93b258b20f..b97f97784e 100644 --- a/sqflite/test/sentry_database_test.dart +++ b/sqflite/test/sentry_database_test.dart @@ -1234,7 +1234,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn); + final options = defaultTestOptions(); final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); final database = MockDatabase(); diff --git a/sqflite/test/sentry_sqflite_database_factory_dart_test.dart b/sqflite/test/sentry_sqflite_database_factory_dart_test.dart index 061660884f..38bc23d404 100644 --- a/sqflite/test/sentry_sqflite_database_factory_dart_test.dart +++ b/sqflite/test/sentry_sqflite_database_factory_dart_test.dart @@ -95,7 +95,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); late final scope = Scope(options); diff --git a/sqflite/test/sentry_sqflite_test.dart b/sqflite/test/sentry_sqflite_test.dart index 41aa3277b9..f54cfda980 100644 --- a/sqflite/test/sentry_sqflite_test.dart +++ b/sqflite/test/sentry_sqflite_test.dart @@ -121,7 +121,7 @@ void main() { class Fixture { final hub = MockHub(); - final options = SentryOptions(dsn: fakeDsn)..tracesSampleRate = 1.0; + final options = defaultTestOptions()..tracesSampleRate = 1.0; final _context = SentryTransactionContext('name', 'operation'); late final tracer = SentryTracer(_context, hub); late final scope = Scope(options); diff --git a/sqflite/test/utils.dart b/sqflite/test/utils.dart index 5dbeee585a..7fb87861f0 100644 --- a/sqflite/test/utils.dart +++ b/sqflite/test/utils.dart @@ -1 +1,8 @@ +import 'package:sentry/sentry.dart'; + final fakeDsn = 'https://abc@def.ingest.sentry.io/1234567'; + +SentryOptions defaultTestOptions() { + // ignore: invalid_use_of_internal_member + return SentryOptions(dsn: fakeDsn)..automatedTestMode = true; +}