Skip to content

Commit 37f7bf2

Browse files
committed
rename test and run all native bridge commands
1 parent 844f08b commit 37f7bf2

File tree

4 files changed

+224
-26
lines changed

4 files changed

+224
-26
lines changed

.github/workflows/flutter_integration_test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
api-level: 21
4141
arch: x86_64
4242
profile: Nexus 6
43-
script: flutter test integration_test/launch_test.dart
43+
script: flutter test integration_test/integration_test.dart
4444
test-ios:
4545
runs-on: macos-latest
4646
defaults:
@@ -70,4 +70,4 @@ jobs:
7070
os_version: '15.2'
7171

7272
- name: run ios integration test
73-
run: flutter test integration_test/launch_test.dart
73+
run: flutter test integration_test/integration_test.dart
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
import 'dart:io';
2+
3+
import 'package:flutter/services.dart';
4+
import 'package:flutter/widgets.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:integration_test/integration_test.dart';
7+
import 'package:sentry_flutter/sentry_flutter.dart';
8+
import 'package:sentry_flutter_example/main.dart';
9+
10+
void main() {
11+
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
12+
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
13+
14+
Future<void> setupSentryAndApp(WidgetTester tester) async {
15+
await setupSentry(() async {
16+
await tester.pumpWidget(DefaultAssetBundle(
17+
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
18+
child: MyApp(),
19+
));
20+
await tester.pumpAndSettle();
21+
});
22+
}
23+
24+
Future<void> executeNative(Future<void> Function(MethodChannel) execute) async {
25+
try {
26+
final channel = MethodChannel('sentry_flutter');
27+
await execute(channel);
28+
} catch (error, stackTrace) {
29+
fail('error: $error stacktrace: $stackTrace');
30+
}
31+
}
32+
33+
// Tests
34+
35+
testWidgets('setup sentry and render app', (tester) async {
36+
await setupSentryAndApp(tester);
37+
38+
// Find any UI element and verify it is present.
39+
expect(find.text('Open another Scaffold'), findsOneWidget);
40+
});
41+
42+
if (Platform.isIOS) {
43+
testWidgets('setup sentry and execute loadContexts', (tester) async {
44+
await setupSentryAndApp(tester);
45+
46+
await executeNative((channel) async {
47+
Map<String, dynamic>.from(
48+
await (channel.invokeMethod('loadContexts')),
49+
);
50+
});
51+
});
52+
}
53+
54+
testWidgets('setup sentry and execute loadImageList', (tester) async {
55+
await setupSentryAndApp(tester);
56+
57+
await executeNative((channel) async {
58+
List<Map<dynamic, dynamic>>.from(
59+
await channel.invokeMethod('loadImageList'),
60+
);
61+
});
62+
});
63+
64+
testWidgets('setup sentry and execute captureEnvelope', (tester) async {
65+
await setupSentryAndApp(tester);
66+
67+
await executeNative((channel) async {
68+
final eventId = SentryId.newId();
69+
final event = SentryEvent(eventId: eventId);
70+
final sdkVersion = SdkVersion(name: 'fixture-sdkName', version: 'fixture-sdkVersion');
71+
final envelope = SentryEnvelope.fromEvent(event, sdkVersion);
72+
final envelopeData = <int>[];
73+
await envelope
74+
.envelopeStream(SentryOptions())
75+
.forEach(envelopeData.addAll);
76+
// https://flutter.dev/docs/development/platform-integration/platform-channels#codec
77+
final args = [Uint8List.fromList(envelopeData)];
78+
79+
final result = await channel.invokeMethod(
80+
'captureEnvelope', args
81+
);
82+
expect(result, ''); // Empty string is returned on success
83+
});
84+
});
85+
86+
testWidgets('setup sentry and execute fetchNativeAppStart', (tester) async {
87+
await setupSentryAndApp(tester);
88+
89+
await executeNative((channel) async {
90+
final result = await channel.invokeMapMethod<String, dynamic>(
91+
'fetchNativeAppStart'
92+
);
93+
expect(result != null, true);
94+
});
95+
});
96+
97+
testWidgets('setup sentry and execute beginNativeFrames & endNativeFrames', (tester) async {
98+
await setupSentryAndApp(tester);
99+
100+
await executeNative((channel) async {
101+
await channel.invokeMethod<void>('beginNativeFrames');
102+
103+
final sentryId = SentryId.empty();
104+
105+
await channel.invokeMapMethod<String, dynamic>(
106+
'endNativeFrames', {'id': sentryId.toString()}
107+
);
108+
});
109+
});
110+
111+
testWidgets('setup sentry and execute setContexts', (tester) async {
112+
await setupSentryAndApp(tester);
113+
114+
await executeNative((channel) async {
115+
final result = await channel.invokeMethod(
116+
'setContexts',
117+
{'key': 'fixture-key', 'value': 'fixture-value'}
118+
);
119+
expect(result, ''); // Empty string is returned on success
120+
});
121+
});
122+
123+
testWidgets('setup sentry and execute setUser', (tester) async {
124+
await setupSentryAndApp(tester);
125+
126+
await executeNative((channel) async {
127+
final result = await channel.invokeMethod(
128+
'setUser',
129+
{'user': null}
130+
);
131+
expect(result, ''); // Empty string is returned on success
132+
});
133+
});
134+
135+
testWidgets('setup sentry and execute addBreadcrumb', (tester) async {
136+
await setupSentryAndApp(tester);
137+
138+
await executeNative((channel) async {
139+
final breadcrumb = Breadcrumb();
140+
final result = await channel.invokeMethod(
141+
'addBreadcrumb',
142+
{'breadcrumb': breadcrumb.toJson()}
143+
);
144+
expect(result, ''); // Empty string is returned on success
145+
});
146+
});
147+
148+
testWidgets('setup sentry and execute clearBreadcrumbs', (tester) async {
149+
await setupSentryAndApp(tester);
150+
151+
await executeNative((channel) async {
152+
final result = await channel.invokeMethod(
153+
'clearBreadcrumbs'
154+
);
155+
expect(result, ''); // Empty string is returned on success
156+
});
157+
});
158+
159+
testWidgets('setup sentry and execute setExtra', (tester) async {
160+
await setupSentryAndApp(tester);
161+
162+
await executeNative((channel) async {
163+
final result = await channel.invokeMethod(
164+
'setExtra',
165+
{'key': 'fixture-key', 'value': 'fixture-value'}
166+
);
167+
expect(result, ''); // Empty string is returned on success
168+
});
169+
});
170+
171+
testWidgets('setup sentry and execute removeExtra', (tester) async {
172+
await setupSentryAndApp(tester);
173+
174+
await executeNative((channel) async {
175+
await channel.invokeMethod(
176+
'setExtra',
177+
{'key': 'fixture-key', 'value': 'fixture-value'}
178+
);
179+
final result = await channel.invokeMethod(
180+
'removeExtra', {'key': 'fixture-key'}
181+
);
182+
expect(result, ''); // Empty string is returned on success
183+
});
184+
});
185+
186+
testWidgets('setup sentry and execute setTag', (tester) async {
187+
await setupSentryAndApp(tester);
188+
189+
await executeNative((channel) async {
190+
final result = await channel.invokeMethod(
191+
'setTag',
192+
{'key': 'fixture-key', 'value': 'fixture-value'}
193+
);
194+
expect(result, ''); // Empty string is returned on success
195+
});
196+
});
197+
198+
testWidgets('setup sentry and execute removeTag', (tester) async {
199+
await setupSentryAndApp(tester);
200+
201+
await executeNative((channel) async {
202+
await channel.invokeMethod(
203+
'setTag',
204+
{'key': 'fixture-key', 'value': 'fixture-value'}
205+
);
206+
final result = await channel.invokeMethod(
207+
'removeTag', {'key': 'fixture-key'}
208+
);
209+
expect(result, ''); // Empty string is returned on success
210+
});
211+
});
212+
213+
testWidgets('setup sentry and execute closeNativeSdk', (tester) async {
214+
await setupSentryAndApp(tester);
215+
216+
await executeNative((channel) async {
217+
final result = await channel.invokeMethod('closeNativeSdk');
218+
expect(result, ''); // Empty string is returned on success
219+
});
220+
});
221+
}

flutter/example/integration_test/launch_test.dart

-23
This file was deleted.

flutter/lib/src/sentry_native_channel.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SentryNativeChannel {
2828

2929
Future<void> beginNativeFrames() async {
3030
try {
31-
await _channel.invokeMapMethod<String, dynamic>('beginNativeFrames');
31+
await _channel.invokeMethod('beginNativeFrames');
3232
} catch (error, stackTrace) {
3333
_logError('beginNativeFrames', error, stackTrace);
3434
}

0 commit comments

Comments
 (0)