Part 1: Skia Gold Testing (#33688)

* Fresh PR for Gold integration.

* Nits

* WIP

* Artifacts from merge

* Changed some platform dependencies for web, added library prefix notation for Skia Gold test names.

* Updating for CI implementation

* Write out service account

* Writing to skip out

* WIP

* ++

* Fixing depot tools deps

* Windows depot_tools

* Fixing setup scripts

* ++

* depot tools

* ++

* WIP

* Tracing depot_tools clone

* WIP

* ++

* analyzer

* WIP

* chrome typo

* copy artifact

* Working on tests

* Code cleanup

* ++

* Code cleanup, updated tests

* ++ review feedback

* Review

* Analyzer

* Review feedback

* Nits from review

* PRogress

* ++

* Fixing tests

* ++

* Testing repo route

* Just needing documention around new structures.

* cleanup

* Analyzer

* Documentation updates

* Documentation updates

* Cirrus updates

* cirrus nit

* Review feedback

* Review feedback

* Fixing skip comparator

* Fix base directory for Skia Gold case

* ++

* Feedback

* ++

* Fixed uri assertion

* Made GoldensClient abstract, altered SkiaGoldClient constructor

* Analyzer
This commit is contained in:
Kate Lovett
2019-07-12 12:23:04 -07:00
committed by GitHub
parent fc7bd6ad24
commit eb0b179028
38 changed files with 671 additions and 268 deletions

View File

@@ -45,6 +45,26 @@ abstract class GoldenFileComparator {
/// The method by which [golden] is located and by which its bytes are written
/// is left up to the implementation class.
Future<void> update(Uri golden, Uint8List imageBytes);
/// Returns a new golden file [Uri] to incorporate any [version] number with
/// the [key].
///
/// The [version] is an optional int that can be used to differentiate
/// historical golden files.
///
/// Version numbers are used in golden file tests for package:flutter. You can
/// learn more about these tests [here](https://github.com/flutter/flutter/wiki/Writing-a-golden-file-test-for-package:flutter).
Uri getTestUri(Uri key, int version) {
if (version == null)
return key;
final String keyString = key.toString();
final String extension = path.extension(keyString);
return Uri.parse(
keyString
.split(extension)
.join() + '.' + version.toString() + extension
);
}
}
/// Compares rasterized image bytes against a golden image file.
@@ -126,6 +146,11 @@ class TrivialComparator implements GoldenFileComparator {
Future<void> update(Uri golden, Uint8List imageBytes) {
throw StateError('goldenFileComparator has not been initialized');
}
@override
Uri getTestUri(Uri key, int version) {
return key;
}
}
/// The default [GoldenFileComparator] implementation for `flutter test`.
@@ -140,7 +165,7 @@ class TrivialComparator implements GoldenFileComparator {
///
/// When using `flutter test --update-goldens`, [LocalFileComparator]
/// updates the files on disk to match the rendering.
class LocalFileComparator implements GoldenFileComparator {
class LocalFileComparator extends GoldenFileComparator {
/// Creates a new [LocalFileComparator] for the specified [testFile].
///
/// Golden file keys will be interpreted as file paths relative to the

View File

@@ -1712,7 +1712,7 @@ class _MatchesGoldenFile extends AsyncMatcher {
imageFuture = _captureImage(elements.single);
}
final Uri testNameUri = _getTestNameUri(key, version);
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
return binding.runAsync<String>(() async {
@@ -1734,19 +1734,9 @@ class _MatchesGoldenFile extends AsyncMatcher {
}
@override
Description describe(Description description) =>
description.add('one widget whose rasterized image matches golden image "${_getTestNameUri(key, version)}"');
Uri _getTestNameUri(Uri key, int version) {
return version == null ? key : Uri.parse(
key
.toString()
.splitMapJoin(
RegExp(r'.png'),
onMatch: (Match m) => '${'.' + version.toString() + m.group(0)}',
onNonMatch: (String n) => '$n'
)
);
Description describe(Description description) {
final Uri testNameUri = goldenFileComparator.getTestUri(key, version);
return description.add('one widget whose rasterized image matches golden image "$testNameUri"');
}
}

View File

@@ -182,5 +182,18 @@ void main() {
expect(fs.file(fix('/foo.png')).readAsBytesSync(), newBytes);
});
});
group('getTestUri', () {
test('updates file name with version number', () {
final Uri key = Uri.parse('foo.png');
final Uri key1 = comparator.getTestUri(key, 1);
expect(key1, Uri.parse('foo.1.png'));
});
test('does nothing for null version number', () {
final Uri key = Uri.parse('foo.png');
final Uri keyNull = comparator.getTestUri(key, null);
expect(keyNull, Uri.parse('foo.png'));
});
});
});
}

View File

@@ -335,30 +335,6 @@ void main() {
expect(comparator.imageBytes, hasLength(greaterThan(0)));
expect(comparator.golden, Uri.parse('foo.png'));
});
testWidgets('Comparator succeeds incorporating version number', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(const Text('hello')));
final Finder finder = find.byType(Text);
await expectLater(finder, matchesGoldenFile(
'foo.png',
version: 1,
));
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(comparator.imageBytes, hasLength(greaterThan(0)));
expect(comparator.golden, Uri.parse('foo.1.png'));
});
testWidgets('Comparator succeeds with null version number', (WidgetTester tester) async {
await tester.pumpWidget(boilerplate(const Text('hello')));
final Finder finder = find.byType(Text);
await expectLater(finder, matchesGoldenFile(
'foo.png',
version: null,
));
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(comparator.imageBytes, hasLength(greaterThan(0)));
expect(comparator.golden, Uri.parse('foo.png'));
});
});
group('does not match', () {
@@ -413,40 +389,6 @@ void main() {
expect(error.message, contains('too many widgets'));
}
});
testWidgets('Comparator failure incorporates version number', (WidgetTester tester) async {
comparator.behavior = _ComparatorBehavior.returnFalse;
await tester.pumpWidget(boilerplate(const Text('hello')));
final Finder finder = find.byType(Text);
try {
await expectLater(finder, matchesGoldenFile(
'foo.png',
version: 1,
));
fail('TestFailure expected but not thrown');
} on TestFailure catch (error) {
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(error.message, contains('does not match'));
expect(error.message, contains('foo.1.png'));
}
});
testWidgets('Comparator failure with null version number', (WidgetTester tester) async {
comparator.behavior = _ComparatorBehavior.returnFalse;
await tester.pumpWidget(boilerplate(const Text('hello')));
final Finder finder = find.byType(Text);
try {
await expectLater(finder, matchesGoldenFile(
'foo.png',
version: null,
));
fail('TestFailure expected but not thrown');
} on TestFailure catch (error) {
expect(comparator.invocation, _ComparatorInvocation.compare);
expect(error.message, contains('does not match'));
expect(error.message, contains('foo.png'));
}
});
});
testWidgets('calls update on comparator if autoUpdateGoldenFiles is true', (WidgetTester tester) async {
@@ -708,6 +650,11 @@ class _FakeComparator implements GoldenFileComparator {
this.imageBytes = imageBytes;
return Future<void>.value();
}
@override
Uri getTestUri(Uri key, int version) {
return key;
}
}
class _FakeSemanticsNode extends SemanticsNode {