-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from Afroz-Shaikh/v1.0.4
V1.0.4
- Loading branch information
Showing
14 changed files
with
130 additions
and
51 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
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
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
2 changes: 1 addition & 1 deletion
2
example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
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
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
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
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
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
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,22 +1,63 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
// All tests in this folder and its subfolders will have the configuration defined here | ||
const _kGoldenTestsThreshold = 10 / 100; // 1% tolerance | ||
|
||
Future<void> testExecutable(FutureOr<void> Function() testMain) async { | ||
return GoldenToolkit.runWithConfiguration( | ||
() async { | ||
await loadAppFonts(); | ||
await testMain(); | ||
}, | ||
config: GoldenToolkitConfiguration( | ||
// Currently, goldens are not generated/validated in CI for this repo. We have settled on the goldens for this package | ||
// being captured/validated by developers running on MacOSX. We may revisit this in the future if there is a reason to invest | ||
// in more sophistication | ||
skipGoldenAssertion: () => !Platform.isMacOS, | ||
enableRealShadows: true, | ||
), | ||
); | ||
if (goldenFileComparator is LocalFileComparator) { | ||
final testUrl = (goldenFileComparator as LocalFileComparator).basedir; | ||
|
||
goldenFileComparator = LocalFileComparatorWithThreshold( | ||
Uri.parse('$testUrl/test. dart'), | ||
_kGoldenTestsThreshold, | ||
); | ||
} else { | ||
throw Exception( | ||
'Expected goldenFileComparator to be of type' | ||
'LocalFileComparator' | ||
'but it is of type ${goldenFileComparator.runtimeType}`', | ||
); | ||
} | ||
await testMain(); | ||
} | ||
|
||
/// Works just like [LocalFileComparator] but includes a [threshold] that, when | ||
/// exceeded, marks the test as a failure. | ||
class LocalFileComparatorWithThreshold extends LocalFileComparator { | ||
/// Threshold above which tests will be marked as failing. | ||
/// Ranges from 0 to 1, both inclusive. | ||
final double threshold; | ||
|
||
LocalFileComparatorWithThreshold(Uri testFile, this.threshold) | ||
: assert(threshold >= 0 && threshold <= 1), | ||
super(testFile); | ||
|
||
/// Copy of [LocalFileComparator]'s [compare] method, except for the fact that | ||
/// it checks if the [ComparisonResult.diffPercent] is not greater than | ||
/// [threshold] to decide whether this test is successful or a failure. | ||
@override | ||
Future<bool> compare(Uint8List imageBytes, Uri golden) async { | ||
final result = await GoldenFileComparator.compareLists( | ||
imageBytes, | ||
await getGoldenBytes(golden), | ||
); | ||
|
||
if (!result.passed && result.diffPercent <= threshold) { | ||
print( | ||
'A difference of ${result.diffPercent * 100}% was found, but it is ' | ||
'acceptable since it is not greater than the threshold of ' | ||
'${threshold * 100}%', | ||
); | ||
|
||
return true; | ||
} | ||
|
||
if (!result.passed) { | ||
final error = await generateFailureOutput(result, golden, basedir); | ||
throw FlutterError(error); | ||
} | ||
return result.passed; | ||
} | ||
} |
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
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
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
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
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