Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeakTesting doesn't exist in leak_tracker_flutter_testing #215

Closed
ValentinVignal opened this issue Jan 27, 2024 · 2 comments · Fixed by #216
Closed

LeakTesting doesn't exist in leak_tracker_flutter_testing #215

ValentinVignal opened this issue Jan 27, 2024 · 2 comments · Fixed by #216

Comments

@ValentinVignal
Copy link
Contributor

ValentinVignal commented Jan 27, 2024

I'm following https://github.com/dart-lang/leak_tracker/blob/main/doc/leak_tracking/DETECT.md :

When using the latest flutter stable:

Flutter 3.16.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 41456452f2 (2 days ago) • 2024-01-25 10:06:23 -0800
Engine • revision f40e976bed
Tools • Dart 3.2.6 • DevTools 2.28.5

and run flutter pub add leak_tracker_flutter_testing in a brand new project, I get the version 2.0.0 of leak_tracker_flutter_testing:

  leak_tracker 9.0.18 (10.0.3 available)
  leak_tracker_flutter_testing 2.0.0 (3.0.2 available)
  leak_tracker_testing 1.0.5 (3.0.0 available)
  matcher 0.12.16 (0.12.16+1 available)
  material_color_utilities 0.5.0 (0.8.0 available)
  meta 1.10.0 (1.11.0 available)
  path 1.8.3 (1.9.0 available)
  test_api 0.6.1 (0.7.0 available)
  web 0.3.0 (0.4.2 available)

When add the test/flutter_test_config.dart:

import 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

FutureOr<void> testExecutable(FutureOr<void> Function() testMain) {
  LeakTesting.enable();
  LeakTesting.settings =
      LeakTesting.settings.withIgnored(createdByTestHelpers: true);

  return testMain();
}

LeakTesting is not defined:

image

Running flutter analyze:

Analyzing flutter_app_stable...                                         

warning • Unused import: 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart' • test/flutter_test_config.dart:3:8 • unused_import
  error • Undefined name 'LeakTesting' • test/flutter_test_config.dart:6:3 • undefined_identifier
  error • Undefined name 'LeakTesting' • test/flutter_test_config.dart:7:3 • undefined_identifier
  error • Undefined name 'LeakTesting' • test/flutter_test_config.dart:8:7 • undefined_identifier

4 issues found. (ran in 2.1s)

You can checkout https://github.com/ValentinVignal/flutter_app_stable/tree/leak_tracker_flutter_testing/Test-on-flutter-3.16

@ValentinVignal
Copy link
Contributor Author

It seems like LeakTesting was removed from leak_tracker_flutter_testing in the version 1.0.10 and added to leak_tracker_testing in the version 1.0.6. But leak_tracker_testing >=1.0.6 depends on meta ^1.11.0 which seems incompatible with flutter stable 3.16.9:

Resolving dependencies... 
Note: meta is pinned to version 1.10.0 by flutter_test from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.


Because every version of flutter_test from sdk depends on meta 1.10.0 and leak_tracker_testing >=1.0.6 depends on meta ^1.11.0, flutter_test from sdk is incompatible with leak_tracker_testing >=1.0.6.
So, because flutter_app_stable depends on both leak_tracker_testing ^1.0.6 and flutter_test from sdk, version solving failed.


You can try the following suggestion to make the pubspec resolve:
* Consider downgrading your constraint on leak_tracker_testing: flutter pub add leak_tracker_testing:^1.0.5

My fix is to change my pubspec.yaml to use leak_tracker_flutter_testing: 1.0.9:

leak_tracker_flutter_testing: 1.0.9

and my test/flutter_test_config.dart becomes:

import 'dart:async';

import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

FutureOr<void> testExecutable(FutureOr<void> Function() testMain) {
  LeakTesting.settings = LeakTesting.settings.withTrackedAll();

  return testMain();
}

However, I tried to add it to go_router https://github.com/flutter/packages/tree/main/packages/go_router and no test is failing, unlike you showed me @polina-c .

Can this package be used on flutter stable 3.16.9?

@polina-c
Copy link
Contributor

Oh, yes, for now leak_tracker works just for flutter starting 3.18.0.
May be it makes it impossible to adopt leak tracker for flutter packages at the moment and it should be postponed..

Thanks for trying and discovering it!!!
Adding to documentation: #216

auto-submit bot pushed a commit that referenced this issue Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants