maybeSetupLeakTrackingForTest function

void maybeSetupLeakTrackingForTest(
  1. LeakTesting? settings,
  2. String testDescription
)

Makes sure leak tracking is set up for a test.

If settings.ignore is true, the method is noop. If leak tracking is not started, starts it. Configures LeakTracking.phase to match settings.

Implementation

void maybeSetupLeakTrackingForTest(
  LeakTesting? settings,
  String testDescription,
) {
  if (!LeakTesting.enabled) return;

  final leakTesting = settings ?? LeakTesting.settings;
  if (leakTesting.ignore) return;

  if (!_checkPlatformAndMayBePrintWarning(
      platformName: defaultTargetPlatform.name, isBrowser: kIsWeb)) {
    return;
  }

  _maybeStartLeakTracking();

  final phase = PhaseSettings(
    name: testDescription,
    leakDiagnosticConfig: leakTesting.leakDiagnosticConfig,
    ignoredLeaks: leakTesting.ignoredLeaks,
    baselining: leakTesting.baselining,
    ignoreLeaks: leakTesting.ignore,
  );

  LeakTracking.phase = phase;
}