forked from firka/flutter
Committing progress.
This commit is contained in:
@@ -14,7 +14,7 @@ import 'package:test_api/test_api.dart' as test_package show TestFailure;
|
||||
|
||||
import 'package:flutter_goldens_client/client.dart';
|
||||
export 'package:flutter_goldens_client/client.dart';
|
||||
//TODO(katelovett): Tests
|
||||
|
||||
const String _kFlutterRootKey = 'FLUTTER_ROOT';
|
||||
|
||||
/// Main method that can be used in a `flutter_test_config.dart` file to set
|
||||
@@ -80,6 +80,10 @@ class FlutterGoldenFileComparator implements GoldenFileComparator {
|
||||
@override
|
||||
Future<bool> compare(Uint8List imageBytes, Uri golden) async {
|
||||
final bool authorized = await _skiaClient.auth(fs.directory(basedir));
|
||||
if(!authorized) {
|
||||
//TODO(katelovett): Clean up for final CI implementation
|
||||
return true;
|
||||
}
|
||||
final File goldenFile = _getGoldenFile(golden);
|
||||
if(!goldenFile.existsSync()) {
|
||||
throw test_package.TestFailure('Could not be compared against non-existent file: "$golden"');
|
||||
|
||||
@@ -17,7 +17,7 @@ const String _kFlutterRoot = '/flutter';
|
||||
const String _kGoldenRoot = '$_kFlutterRoot/bin/cache/pkg/goldens';
|
||||
//const String _kVersionFile = '$_kFlutterRoot/bin/internal/goldens.version';
|
||||
//const String _kGoldensVersion = '123456abcdef';
|
||||
|
||||
//TODO(katelovett): Finish testing
|
||||
void main() {
|
||||
MemoryFileSystem fs;
|
||||
FakePlatform platform;
|
||||
@@ -27,7 +27,10 @@ void main() {
|
||||
|
||||
setUp(() async {
|
||||
fs = MemoryFileSystem();
|
||||
platform = FakePlatform(environment: <String, String>{'FLUTTER_ROOT': _kFlutterRoot});
|
||||
platform = FakePlatform(environment: <String, String>{
|
||||
'FLUTTER_ROOT': _kFlutterRoot,
|
||||
//TODO Add other env vars for testing
|
||||
});
|
||||
process = MockProcessManager();
|
||||
flutter = await fs.directory(_kFlutterRoot).create(recursive: true);
|
||||
golden = await fs.directory(_kGoldenRoot).create(recursive: true);
|
||||
@@ -87,8 +90,8 @@ void main() {
|
||||
|
||||
test('throws if goldctl has not been authorized', () async {
|
||||
// Create file
|
||||
final File goldenFile = fs.file('/path/to/flutter/bin/cache/goldens/test/foo/bar/test.png')
|
||||
..createSync(recursive: true);
|
||||
//final File goldenFile = fs.file('/path/to/flutter/bin/cache/goldens/test/foo/bar/test.png')
|
||||
//s ..createSync(recursive: true);
|
||||
try {
|
||||
await comparator.compare(Uint8List.fromList(<int>[1, 2, 3]), Uri.parse('test.png'));
|
||||
fail('TestFailure expected but not thrown');
|
||||
|
||||
@@ -14,7 +14,7 @@ import 'package:process/process.dart';
|
||||
// If you are here trying to figure out how to use golden files in the Flutter
|
||||
// repo itself, consider reading this wiki page:
|
||||
// https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package%3Aflutter
|
||||
//TODO(katelovett): Tests
|
||||
|
||||
const String _kFlutterRootKey = 'FLUTTER_ROOT';
|
||||
const String _kGoldctlKey = 'GOLDCTL';
|
||||
const String _kServiceAccountKey = 'GOLD_SERVICE_ACCOUNT';
|
||||
@@ -79,8 +79,10 @@ class SkiaGoldClient {
|
||||
Future<bool> auth(Directory workDirectory) async {
|
||||
_workDirectory = workDirectory;
|
||||
List<String> authArguments = <String>['auth'];
|
||||
//TODO(katelovett): Cleanup for final CI implementation
|
||||
if(_serviceAccount == null)
|
||||
throw const NonZeroExitCode(1, 'No Service Account found.');
|
||||
return false;
|
||||
//throw const NonZeroExitCode(1, 'No Service Account found.');
|
||||
|
||||
authArguments += <String>[
|
||||
'--service-account', _serviceAccount,
|
||||
@@ -99,7 +101,6 @@ class SkiaGoldClient {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Future<bool> imgtest(String testName, File goldenFile) async {
|
||||
List<String> imgtestArguments = <String>[
|
||||
'imgtest',
|
||||
|
||||
@@ -296,7 +296,34 @@ AsyncMatcher matchesGoldenFile(dynamic key) {
|
||||
throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}');
|
||||
}
|
||||
|
||||
/// TODO(katelovett): Documentation
|
||||
/// Asserts that a [Finder], [Future<ui.Image>], or [ui.Image] matches the
|
||||
/// golden image file identified by [key] through Skia Gold.
|
||||
///
|
||||
/// For the case of a [Finder], the [Finder] must match exactly one widget and
|
||||
/// the rendered image of the first [RepaintBoundary] ancestor of the widget is
|
||||
/// treated as the image for the widget.
|
||||
///
|
||||
/// [key] may be either a [Uri] or a [String] representation of a URI.
|
||||
///
|
||||
/// This is an asynchronous matcher, meaning that callers should use
|
||||
/// [expectLater] when using this matcher and await the future returned by
|
||||
/// [expectLater].
|
||||
///
|
||||
/// ## Sample code
|
||||
///
|
||||
/// ```dart
|
||||
/// await expectLater(find.text('Save'), matchesSkiaGoldFile('save.png'));
|
||||
/// await expectLater(image, matchesSkiaGoldFile('save.png'));
|
||||
/// await expectLater(imageFuture, matchesSkiaGoldFile('save.png'));
|
||||
/// ```
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [FlutterGoldenFileComparator], which acts as the backend for this matcher.
|
||||
/// * [SkiaGoldClient], which the [FlutterGoldenFileComparator] uses to execute
|
||||
/// and process results of testing with Skia Gold.
|
||||
/// * [flutter_test] for a discussion of test configurations, whereby callers
|
||||
/// may swap out the backend for this matcher.
|
||||
AsyncMatcher matchesSkiaGoldFile(dynamic key) {
|
||||
if (key is Uri) {
|
||||
return _MatchesSkiaGoldFile(key);
|
||||
|
||||
@@ -136,13 +136,13 @@ class UpdatePackagesCommand extends FlutterCommand {
|
||||
// The dev/integration_tests/android_views integration test depends on an assets
|
||||
// package that is in the goldens repository. We need to make sure that the goldens
|
||||
// repository is cloned locally before we verify or update pubspecs.
|
||||
printStatus('Cloning goldens repository...');
|
||||
try {
|
||||
final GoldensClient goldensClient = GoldensClient();
|
||||
await goldensClient.prepare();
|
||||
} on NonZeroExitCode catch (e) {
|
||||
throwToolExit(e.stderr, exitCode: e.exitCode);
|
||||
}
|
||||
// printStatus('Cloning goldens repository...');
|
||||
// try {
|
||||
// final GoldensClient goldensClient = GoldensClient();
|
||||
// await goldensClient.prepare();
|
||||
// } on NonZeroExitCode catch (e) {
|
||||
// throwToolExit(e.stderr, exitCode: e.exitCode);
|
||||
// }
|
||||
|
||||
if (isVerifyOnly) {
|
||||
bool needsUpdate = false;
|
||||
|
||||
Reference in New Issue
Block a user