-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override GoldenComperator with tolerance to fix problem on CI.
- Loading branch information
1 parent
c070451
commit 33d18b5
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
|
||
import 'golden_diff_comparator.dart'; | ||
import 'test_app.dart'; | ||
|
||
Future<void> testExecutable(FutureOr<void> Function() testMain) async => | ||
GoldenToolkit.runWithConfiguration( | ||
() => TestApp.setupAll().then((value) => testMain()), | ||
config: GoldenToolkitConfiguration(skipGoldenAssertion: () => false), | ||
); | ||
Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
final testUrl = (goldenFileComparator as LocalFileComparator).basedir; | ||
goldenFileComparator = GoldenDiffComparator('$testUrl/test.dart'); | ||
GoldenToolkit.runWithConfiguration( | ||
() => TestApp.setupAll().then((value) => testMain()), | ||
config: GoldenToolkitConfiguration(skipGoldenAssertion: () => false), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
class GoldenDiffComparator extends LocalFileComparator { | ||
GoldenDiffComparator( | ||
String testFile, { | ||
this.tolerance = 0.005, | ||
}) : super(Uri.parse(testFile)); | ||
|
||
final double tolerance; | ||
|
||
@override | ||
Future<bool> compare(Uint8List imageBytes, Uri golden) async { | ||
final ComparisonResult result = await GoldenFileComparator.compareLists( | ||
imageBytes, | ||
await getGoldenBytes(golden), | ||
); | ||
|
||
if (!result.passed && result.diffPercent > tolerance) { | ||
final String error = await generateFailureOutput(result, golden, basedir); | ||
throw FlutterError(error); | ||
} | ||
if (!result.passed) { | ||
log('A tolerable difference of ${result.diffPercent * 100}% was found when comparing $golden.'); | ||
} | ||
return result.passed || result.diffPercent <= tolerance; | ||
} | ||
} |