Skip to content

Commit

Permalink
enha: Flutter min version test (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Nov 18, 2022
1 parent cdf7172 commit ccc09e4
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 28 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/flutter_integration_test.yml
@@ -0,0 +1,81 @@
name: flutter integration tests
on:
push:
branches:
- main
pull_request:

jobs:
cancel-previous-workflow:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # pin@0.11.0
with:
access_token: ${{ github.token }}

test-android:
runs-on: macos-latest
defaults:
run:
working-directory: ./flutter/example
strategy:
matrix:
sdk: ['stable', 'beta']
steps:
- name: checkout
uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '8'

- uses: subosito/flutter-action@1e6ee87cb840500837bcd50a667fb28815d8e310 # pin@v2
with:
channel: ${{ matrix.sdk }}

- name: flutter upgrade
run: flutter upgrade

- name: flutter pub get
run: flutter pub get

- name: launch android emulator & run android integration test
uses: reactivecircus/android-emulator-runner@d7b53ddc6e44254e1f4cf4a6ad67345837027a66 #pin@v2.26.0
with:
working-directory: ./flutter/example
api-level: 21
arch: x86_64
profile: Nexus 6
script: flutter test integration_test/integration_test.dart
test-ios:
runs-on: macos-11
defaults:
run:
working-directory: ./flutter/example
strategy:
matrix:
sdk: ['stable', 'beta']
steps:
- name: checkout
uses: actions/checkout@v3

- uses: subosito/flutter-action@1e6ee87cb840500837bcd50a667fb28815d8e310 # pin@v2
with:
channel: ${{ matrix.sdk }}

- name: flutter upgrade
run: flutter upgrade

- name: flutter pub get
run: flutter pub get

- name: launch ios emulator
uses: futureware-tech/simulator-action@ee05c113b79f056b47f354d7b313555f5491e158 #pin@v2
with:
model: 'iPhone 8'
os_version: '15.2'

- name: run ios integration test
run: flutter test integration_test/integration_test.dart
124 changes: 124 additions & 0 deletions flutter/example/integration_test/integration_test.dart
@@ -0,0 +1,124 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:sentry_flutter_example/main.dart';

void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;

Future<void> setupSentryAndApp(WidgetTester tester) async {
await setupSentry(() async {
await tester.pumpWidget(SentryScreenshotWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
child: MyApp(),
)));
await tester.pumpAndSettle();
});
}

// Tests

testWidgets('setup sentry and render app', (tester) async {
await setupSentryAndApp(tester);

// Find any UI element and verify it is present.
expect(find.text('Open another Scaffold'), findsOneWidget);
});

testWidgets('setup sentry and capture event', (tester) async {
await setupSentryAndApp(tester);

final event = SentryEvent();
final sentryId = await Sentry.captureEvent(event);

expect(sentryId != SentryId.empty(), true);
});

testWidgets('setup sentry and capture exception', (tester) async {
await setupSentryAndApp(tester);

try {
throw SentryException(
type: 'StarError', value: 'I have a bad feeling about this...');
} catch (exception, stacktrace) {
final sentryId =
await Sentry.captureException(exception, stackTrace: stacktrace);

expect(sentryId != SentryId.empty(), true);
}
});

testWidgets('setup sentry and capture message', (tester) async {
await setupSentryAndApp(tester);

final sentryId = await Sentry.captureMessage('hello world!');

expect(sentryId != SentryId.empty(), true);
});

testWidgets('setup sentry and capture user feedback', (tester) async {
await setupSentryAndApp(tester);

final feedback = SentryUserFeedback(
eventId: SentryId.newId(),
name: 'fixture-name',
email: 'fixture@email.com',
comments: 'fixture-comments');
await Sentry.captureUserFeedback(feedback);
});

testWidgets('setup sentry and close', (tester) async {
await setupSentryAndApp(tester);

await Sentry.close();
});

testWidgets('setup sentry and add breadcrumb', (tester) async {
await setupSentryAndApp(tester);

final breadcrumb = Breadcrumb(message: 'fixture-message');
await Sentry.addBreadcrumb(breadcrumb);
});

testWidgets('setup sentry and configure scope', (tester) async {
await setupSentryAndApp(tester);

await Sentry.configureScope((scope) async {
await scope.setContexts('contexts-key', 'contexts-value');
await scope.removeContexts('contexts-key');

final user = SentryUser(id: 'fixture-id');
await scope.setUser(user);
await scope.setUser(null);

final breadcrumb = Breadcrumb(message: 'fixture-message');
await scope.addBreadcrumb(breadcrumb);
await scope.clearBreadcrumbs();

await scope.setExtra('extra-key', 'extra-value');
await scope.removeExtra('extra-key');

await scope.setTag('tag-key', 'tag-value');
await scope.removeTag('tag-key');
});
});

testWidgets('setup sentry and start transaction', (tester) async {
await setupSentryAndApp(tester);

final transaction = Sentry.startTransaction('transaction', 'test');
await transaction.finish();
});

testWidgets('setup sentry and start transaction with context',
(tester) async {
await setupSentryAndApp(tester);

final context = SentryTransactionContext('transaction', 'test');
final transaction = Sentry.startTransactionWithContext(context);
await transaction.finish();
});
}
52 changes: 27 additions & 25 deletions flutter/example/lib/main.dart
Expand Up @@ -21,32 +21,34 @@ const String _exampleDsn =
final _channel = const MethodChannel('example.flutter.sentry.io');

Future<void> main() async {
await SentryFlutter.init(
(options) {
options.dsn = _exampleDsn;
options.tracesSampleRate = 1.0;
options.reportPackages = false;
options.addInAppInclude('sentry_flutter_example');
options.considerInAppFramesByDefault = false;
options.attachThreads = true;
options.enableWindowMetricBreadcrumbs = true;
options.addIntegration(LoggingIntegration());
options.attachScreenshot = true;
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.debug = true;
},
// Init your App.
appRunner: () => runApp(
SentryScreenshotWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
child: MyApp(),
await setupSentry(() => runApp(
SentryScreenshotWidget(
child: DefaultAssetBundle(
bundle: SentryAssetBundle(enableStructuredDataTracing: true),
child: MyApp(),
),
),
),
),
);
));
}

Future<void> setupSentry(AppRunner appRunner) async {
await SentryFlutter.init((options) {
options.dsn = _exampleDsn;
options.tracesSampleRate = 1.0;
options.reportPackages = false;
options.addInAppInclude('sentry_flutter_example');
options.considerInAppFramesByDefault = false;
options.attachThreads = true;
options.enableWindowMetricBreadcrumbs = true;
options.addIntegration(LoggingIntegration());
options.attachScreenshot = true;
// We can enable Sentry debug logging during development. This is likely
// going to log too much for your app, but can be useful when figuring out
// configuration issues, e.g. finding out why your events are not uploaded.
options.debug = true;
},
// Init your App.
appRunner: appRunner);
}

class MyApp extends StatefulWidget {
Expand Down
4 changes: 4 additions & 0 deletions flutter/example/pubspec.yaml
Expand Up @@ -25,6 +25,10 @@ dependencies:
dev_dependencies:
pedantic: ^1.11.1
sentry_dart_plugin: ^1.0.0-beta.1
integration_test:
sdk: flutter
flutter_test:
sdk: flutter

flutter:
uses-material-design: true
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/sentry_native_channel.dart
Expand Up @@ -28,7 +28,7 @@ class SentryNativeChannel {

Future<void> beginNativeFrames() async {
try {
await _channel.invokeMapMethod<String, dynamic>('beginNativeFrames');
await _channel.invokeMethod('beginNativeFrames');
} catch (error, stackTrace) {
_logError('beginNativeFrames', error, stackTrace);
}
Expand Down
3 changes: 1 addition & 2 deletions flutter/test/sentry_native_channel_test.dart
Expand Up @@ -37,8 +37,7 @@ void main() {
final sut = fixture.getSut();
await sut.beginNativeFrames();

verify(fixture.methodChannel
.invokeMapMethod<String, dynamic>('beginNativeFrames'));
verify(fixture.methodChannel.invokeMethod('beginNativeFrames'));
});

test('endNativeFrames', () async {
Expand Down

0 comments on commit ccc09e4

Please sign in to comment.