expectMatches static method

Future<void> expectMatches(
  1. FrameGuardReport report,
  2. String name, {
  3. String directory = defaultDirectory,
  4. ComparisonThresholds thresholds = const ComparisonThresholds(),
  5. bool requireMatchingEnvironment = false,
})

Expects report to match the golden baseline named name.

If the baseline is missing, throws with instructions to generate it.

Implementation

static Future<void> expectMatches(
  FrameGuardReport report,
  String name, {
  String directory = defaultDirectory,
  ComparisonThresholds thresholds = const ComparisonThresholds(),
  bool requireMatchingEnvironment = false,
}) async {
  final file = File(p.join(directory, '$name.json'));
  if (!file.existsSync()) {
    throw StateError(
      'Missing baseline.\n'
      'Generate from a known-good report with:\n'
      '  dart run frameguard baseline update <report.json> --out ${file.path}\n'
      'Or call FrameGuardGolden.update(report, \'$name\', overwrite: true).',
    );
  }
  final baseline = await FrameGuardBaseline.load(file);
  final result = FrameGuardCompare(
    thresholds: thresholds,
    requireMatchingEnvironment: requireMatchingEnvironment,
  ).compareReportToBaseline(report, baseline);
  if (result.isRegression) {
    throw TestFailure(result.summary());
  }
}