setupFileComparatorWithThreshold function

void setupFileComparatorWithThreshold([
  1. double goldenTestsThreshold = _kGoldenTestsThreshold
])

Source : https://blog.rows.com/p/writing-a-localfilecomparator-with?s=r Since GitHub Actions does not support ARM machines and the difference in our failing golden tests was never greater than _kGoldenTestsThreshold%, we decided to compromise and add a threshold of 0.03% in golden tests.

Implementation

void setupFileComparatorWithThreshold([
  double goldenTestsThreshold = _kGoldenTestsThreshold,
]) {
  if (goldenFileComparator is LocalFileComparator) {
    final testUrl = (goldenFileComparator as LocalFileComparator).basedir;

    goldenFileComparator = LocalFileComparatorWithThreshold(
      // flutter_test's LocalFileComparator expects the test's URI to be passed
      // as an argument, but it only uses it to parse the baseDir in order to
      // obtain the directory where the golden tests will be placed.
      // As such, we use the default `testUrl`, which is only the `baseDir` and
      // append a generically named `test.dart` so that the `baseDir` is
      // properly extracted.
      Uri.parse('$testUrl/test.dart'),
      goldenTestsThreshold,
    );
  } else {
    throw Exception(
      'Expected `goldenFileComparator` to be of type `LocalFileComparator`, '
      'but it is of type `${goldenFileComparator.runtimeType}`',
    );
  }
}