@@ -11,6 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
11
11
import 'package:mockito/mockito.dart' ;
12
12
import 'package:sentry_flutter/sentry_flutter.dart' ;
13
13
import 'package:sentry_flutter/src/native/factory.dart' ;
14
+ import 'package:sentry_flutter/src/native/native_memory.dart' ;
14
15
import 'package:sentry_flutter/src/native/sentry_native_binding.dart' ;
15
16
16
17
import '../mocks.dart' ;
@@ -76,29 +77,35 @@ void main() {
76
77
await sut.init (hub);
77
78
});
78
79
79
- test ('sets replay ID to context' , () async {
80
- // verify there was no scope configured before
81
- verifyNever (hub.configureScope (any));
82
-
83
- // emulate the native platform invoking the method
84
- await native .invokeFromNative (
85
- mockPlatform.isAndroid
86
- ? 'ReplayRecorder.start'
87
- : 'captureReplayScreenshot' ,
88
- replayConfig);
80
+ testWidgets ('sets replayID to context' , (tester) async {
81
+ await tester.runAsync (() async {
82
+ // verify there was no scope configured before
83
+ verifyNever (hub.configureScope (any));
84
+ when (hub.configureScope (captureAny)).thenReturn (null );
89
85
90
- // verify the replay ID was set
91
- final closure =
92
- verify (hub.configureScope (captureAny)).captured.single;
93
- final scope = Scope (options);
94
- expect (scope.replayId, isNull);
95
- await closure (scope);
96
- expect (scope.replayId.toString (), replayConfig['replayId' ]);
86
+ // emulate the native platform invoking the method
87
+ final future = native .invokeFromNative (
88
+ mockPlatform.isAndroid
89
+ ? 'ReplayRecorder.start'
90
+ : 'captureReplayScreenshot' ,
91
+ replayConfig);
92
+ await tester.pumpAndSettle (const Duration (seconds: 1 ));
93
+ await future;
94
+
95
+ // verify the replay ID was set
96
+ final closure =
97
+ verify (hub.configureScope (captureAny)).captured.single;
98
+ final scope = Scope (options);
99
+ expect (scope.replayId, isNull);
100
+ await closure (scope);
101
+ expect (scope.replayId.toString (), replayConfig['replayId' ]);
102
+ });
97
103
});
98
104
99
105
test ('clears replay ID from context' , () async {
100
106
// verify there was no scope configured before
101
107
verifyNever (hub.configureScope (any));
108
+ when (hub.configureScope (captureAny)).thenReturn (null );
102
109
103
110
// emulate the native platform invoking the method
104
111
await native .invokeFromNative ('ReplayRecorder.stop' );
@@ -116,6 +123,7 @@ void main() {
116
123
testWidgets ('captures images' , (tester) async {
117
124
await tester.runAsync (() async {
118
125
when (hub.configureScope (captureAny)).thenReturn (null );
126
+
119
127
await pumpTestElement (tester);
120
128
pumpAndSettle () => tester.pumpAndSettle (const Duration (seconds: 1 ));
121
129
@@ -198,17 +206,23 @@ void main() {
198
206
expect (capturedImages, equals (fsImages ()));
199
207
expect (capturedImages.length, count);
200
208
} else if (mockPlatform.isIOS) {
201
- var imagaData = native .invokeFromNative (
202
- 'captureReplayScreenshot' , replayConfig);
203
- await pumpAndSettle ();
204
- expect ((await imagaData)? .lengthInBytes, greaterThan (3000 ));
209
+ Future <void > captureAndVerify () async {
210
+ final future = native .invokeFromNative (
211
+ 'captureReplayScreenshot' , replayConfig);
212
+ await pumpAndSettle ();
213
+ final json = (await future) as Map <dynamic , dynamic >;
214
+
215
+ expect (json['length' ], greaterThan (3000 ));
216
+ expect (json['address' ], greaterThan (0 ));
217
+ NativeMemory .fromJson (json).free ();
218
+ }
219
+
220
+ await captureAndVerify ();
205
221
206
- // Happens if the session-replay rate is 0.
222
+ // Check everything works if session-replay rate is 0,
223
+ // which causes replayId to be 0 as well.
207
224
replayConfig['replayId' ] = null ;
208
- imagaData = native .invokeFromNative (
209
- 'captureReplayScreenshot' , replayConfig);
210
- await pumpAndSettle ();
211
- expect ((await imagaData)? .lengthInBytes, greaterThan (3000 ));
225
+ await captureAndVerify ();
212
226
} else {
213
227
fail ('unsupported platform' );
214
228
}
0 commit comments