compare method
Compares the pixels of decoded png imageBytes
against the golden file
identified by golden
.
The returned future completes with a boolean value that indicates whether
the pixels decoded from imageBytes
match the golden file's pixels.
In the case of comparison mismatch, the comparator may choose to throw a TestFailure if it wants to control the failure message, often in the form of a ComparisonResult that provides detailed information about the mismatch.
The method by which golden
is located and by which its bytes are loaded
is left up to the implementation class. For instance, some implementations
may load files from the local file system, whereas others may load files
over the network or from a remote repository.
Implementation
@override
Future<bool> compare(Uint8List imageBytes, Uri golden) async {
final result = await GoldenFileComparator.compareLists(
imageBytes,
await getGoldenBytes(golden),
);
if (!result.passed && result.diffPercent >= tolerance) {
final 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.',
level: 2000,
);
}
return result.passed || result.diffPercent <= tolerance;
}