Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c committed Jul 30, 2023
1 parent ce908ee commit ee12332
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
46 changes: 46 additions & 0 deletions pkgs/leak_tracker_flutter_test/test/end_to_end/no_config_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker/leak_tracker.dart';

import '../test_infra/flutter_classes.dart';
import '../test_infra/leak_tracking_in_flutter.dart';

const test0TrackingOff = 'test0, tracking-off';
const test1TrackingOn = 'test1, tracking-on';
const test2TrackingOff = 'test2, tracking-off';
const test3TrackingOn = 'test3, tracking-on';

/// Tests with default leak tracking configuration.
///
/// This set of tests verifies that if `testWidgetsWithLeakTracking` is used at least once,
/// leak tracking is configured as expected, and is noop for `testWidgets`.
void main() {
testWidgets(test0TrackingOff, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, null);
expect(LeakTracking.phase.isPaused, true);
await widgetTester.pumpWidget(StatelessLeakingWidget());
});

testWidgetsWithLeakTracking(test1TrackingOn, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, test1TrackingOn);
expect(LeakTracking.phase.isPaused, false);
});

testWidgets(test2TrackingOff, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, null);
expect(LeakTracking.phase.isPaused, true);
await widgetTester.pumpWidget(StatelessLeakingWidget());
});

testWidgetsWithLeakTracking(test3TrackingOn, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, test3TrackingOn);
expect(LeakTracking.phase.isPaused, false);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ import 'flutter_test_config_test.dart';
///
/// See https://api.flutter.dev/flutter/flutter_test/flutter_test-library.html.
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
var leakTrackingConfigurationVerified = false;

configureLeakTrackingTearDown(
onLeaks: (leaks) {
try {
expect(leaks, isEmpty);
} catch (e) {
leakTrackingConfigurationVerified = true;
}
},
);

setUpAll(() {
LeakTracking.warnForNotSupportedPlatforms = false;
});

tearDownAll(() async {
expect(leakTrackingConfigurationVerified, true);
});

// tearDownAll(() async {
// try {
// await tearDownTestingWithLeakTracking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ void main() {
// });

testWidgets(test2TrackingOff, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, null);
expect(LeakTracking.phase.isPaused, true);

await widgetTester.pumpWidget(StatelessLeakingWidget());
});

testWidgetsWithLeakTracking(test3TrackingOn, (widgetTester) async {
expect(LeakTracking.isStarted, true);
expect(LeakTracking.phase.name, test3TrackingOn);
expect(LeakTracking.phase.isPaused, false);
await widgetTester.pumpWidget(StatelessLeakingWidget());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void configureLeakTrackingTearDown({
if (_tearDownConfigured) {
throw StateError('Leak tracking tear down is already configured.');
}
tearDownAll(() async => await _tearDownTestingWithLeakTracking(onLeaks));
if (_isPlatformSupported) {
tearDownAll(() async => await _tearDownTestingWithLeakTracking(onLeaks));
}
_tearDownConfigured = true;
}

Expand Down

0 comments on commit ee12332

Please sign in to comment.