diff --git a/dart/lib/src/platform/_web_platform.dart b/dart/lib/src/platform/_web_platform.dart index 56325fa25b..b1cf71f0b5 100644 --- a/dart/lib/src/platform/_web_platform.dart +++ b/dart/lib/src/platform/_web_platform.dart @@ -1,3 +1,4 @@ +import 'package:platform/platform.dart'; import 'package:web/web.dart' as web; import 'platform.dart'; diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index a9c3ea48f9..2571fc0189 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -26,6 +26,7 @@ dependencies: uuid: '>=3.0.0 <5.0.0' collection: ^1.16.0 web: ^1.1.0 + platform: ^3.1.6 dev_dependencies: build_runner: ^2.3.0 diff --git a/dart/test/mocks/mock_platform.dart b/dart/test/mocks/mock_platform.dart new file mode 100644 index 0000000000..26f6f5c8b5 --- /dev/null +++ b/dart/test/mocks/mock_platform.dart @@ -0,0 +1,23 @@ +import 'package:platform/platform.dart'; + +extension MockPlatform on FakePlatform { + static Platform android() { + return FakePlatform(operatingSystem: 'android'); + } + + static Platform iOS() { + return FakePlatform(operatingSystem: 'ios'); + } + + static Platform macOS() { + return FakePlatform(operatingSystem: 'macos'); + } + + static Platform linux() { + return FakePlatform(operatingSystem: 'linux'); + } + + static Platform windows() { + return FakePlatform(operatingSystem: 'windows'); + } +} diff --git a/dart/test/mocks/mock_platform_checker.dart b/dart/test/mocks/mock_platform_checker.dart new file mode 100644 index 0000000000..8cef300026 --- /dev/null +++ b/dart/test/mocks/mock_platform_checker.dart @@ -0,0 +1,40 @@ +import 'package:platform/platform.dart'; +import 'package:sentry/src/platform_checker.dart'; + +import 'no_such_method_provider.dart'; + +class MockPlatformChecker extends PlatformChecker with NoSuchMethodProvider { + MockPlatformChecker({ + this.isDebug = false, + this.isProfile = false, + this.isRelease = false, + this.isWebValue = false, + this.hasNativeIntegration = false, + Platform? platform, + }) : _platform = platform; + + final Platform? _platform; + + final bool isDebug; + final bool isProfile; + final bool isRelease; + final bool isWebValue; + + @override + bool hasNativeIntegration = false; + + @override + bool isDebugMode() => isDebug; + + @override + bool isProfileMode() => isProfile; + + @override + bool isReleaseMode() => isRelease; + + @override + bool get isWeb => isWebValue; + + @override + Platform get platform => _platform ?? super.platform; +} diff --git a/flutter/test/profiling_test.dart b/flutter/test/profiling_test.dart index 1091f893f1..864faef4c5 100644 --- a/flutter/test/profiling_test.dart +++ b/flutter/test/profiling_test.dart @@ -21,6 +21,7 @@ void main() { Hub hubWithSampleRate(double profilesSampleRate) { final o = defaultTestOptions(); o.platform = MockPlatform.iOS(); + o.profilesSampleRate = profilesSampleRate; final hub = MockHub();