@@ -14,6 +14,9 @@ void main() {
14
14
TestWidgetsFlutterBinding .ensureInitialized ();
15
15
late Fixture fixture;
16
16
17
+ late SentryEvent event;
18
+ late Hint hint;
19
+
17
20
setUp (() {
18
21
fixture = Fixture ();
19
22
});
@@ -34,8 +37,8 @@ void main() {
34
37
textDirection: TextDirection .ltr)));
35
38
36
39
final throwable = Exception ();
37
- final event = SentryEvent (throwable: throwable);
38
- final hint = Hint ();
40
+ event = SentryEvent (throwable: throwable);
41
+ hint = Hint ();
39
42
await sut.apply (event, hint: hint);
40
43
41
44
expect (hint.screenshot != null , added);
@@ -91,6 +94,87 @@ void main() {
91
94
await _addScreenshotAttachment (tester, null ,
92
95
added: true , isWeb: false , expectedMaxWidthOrHeight: widthOrHeight);
93
96
});
97
+
98
+ group ('beforeScreenshot' , () {
99
+ testWidgets ('does add screenshot if beforeScreenshot returns true' ,
100
+ (tester) async {
101
+ fixture.options.beforeScreenshot = (SentryEvent event, {Hint ? hint}) {
102
+ return true ;
103
+ };
104
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
105
+ added: true , isWeb: false );
106
+ });
107
+
108
+ testWidgets ('does add screenshot if async beforeScreenshot returns true' ,
109
+ (tester) async {
110
+ fixture.options.beforeScreenshot =
111
+ (SentryEvent event, {Hint ? hint}) async {
112
+ await Future <void >.delayed (Duration (milliseconds: 1 ));
113
+ return true ;
114
+ };
115
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
116
+ added: true , isWeb: false );
117
+ });
118
+
119
+ testWidgets ('does not add screenshot if beforeScreenshot returns false' ,
120
+ (tester) async {
121
+ fixture.options.beforeScreenshot = (SentryEvent event, {Hint ? hint}) {
122
+ return false ;
123
+ };
124
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
125
+ added: false , isWeb: false );
126
+ });
127
+
128
+ testWidgets (
129
+ 'does not add screenshot if async beforeScreenshot returns false' ,
130
+ (tester) async {
131
+ fixture.options.beforeScreenshot =
132
+ (SentryEvent event, {Hint ? hint}) async {
133
+ await Future <void >.delayed (Duration (milliseconds: 1 ));
134
+ return false ;
135
+ };
136
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
137
+ added: false , isWeb: false );
138
+ });
139
+
140
+ testWidgets ('does add screenshot if beforeScreenshot throws' ,
141
+ (tester) async {
142
+ fixture.options.beforeScreenshot = (SentryEvent event, {Hint ? hint}) {
143
+ throw Error ();
144
+ };
145
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
146
+ added: true , isWeb: false );
147
+ });
148
+
149
+ testWidgets ('does add screenshot if async beforeScreenshot throws' ,
150
+ (tester) async {
151
+ fixture.options.beforeScreenshot =
152
+ (SentryEvent event, {Hint ? hint}) async {
153
+ await Future <void >.delayed (Duration (milliseconds: 1 ));
154
+ throw Error ();
155
+ };
156
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
157
+ added: true , isWeb: false );
158
+ });
159
+
160
+ testWidgets ('passes event & hint to beforeScreenshot callback' ,
161
+ (tester) async {
162
+ SentryEvent ? beforeScreenshotEvent;
163
+ Hint ? beforeScreenshotHint;
164
+
165
+ fixture.options.beforeScreenshot = (SentryEvent event, {Hint ? hint}) {
166
+ beforeScreenshotEvent = event;
167
+ beforeScreenshotHint = hint;
168
+ return true ;
169
+ };
170
+
171
+ await _addScreenshotAttachment (tester, FlutterRenderer .canvasKit,
172
+ added: true , isWeb: false );
173
+
174
+ expect (beforeScreenshotEvent, event);
175
+ expect (beforeScreenshotHint, hint);
176
+ });
177
+ });
94
178
}
95
179
96
180
class Fixture {
0 commit comments