dart-lang / leak_tracker

A framework for memory leak tracking for Dart and Flutter applications.
https://pub.dev/packages/leak_tracker
BSD 3-Clause "New" or "Revised" License
396 stars 23 forks source link

`LeakTesting` doesn't exist in `leak_tracker_flutter_testing` #215

Closed ValentinVignal closed 9 months ago

ValentinVignal commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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: https://github.com/dart-lang/leak_tracker/pull/216