From 51fa704642774c6b6ae64c91642b62801e233e1b Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Sat, 19 Sep 2020 11:27:04 -0700 Subject: [PATCH] Add handling for empty expectation (#66142) --- .../flutter_goldens/lib/flutter_goldens.dart | 2 +- .../test/flutter_goldens_test.dart | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/flutter_goldens/lib/flutter_goldens.dart b/packages/flutter_goldens/lib/flutter_goldens.dart index a0ce417613..fb8010d509 100644 --- a/packages/flutter_goldens/lib/flutter_goldens.dart +++ b/packages/flutter_goldens/lib/flutter_goldens.dart @@ -648,7 +648,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC late String? testExpectation; testExpectation = await skiaClient.getExpectationForTest(testName); - if (testExpectation == null) { + if (testExpectation == null || testExpectation.isEmpty) { // There is no baseline for this test print('No expectations provided by Skia Gold for test: $golden. ' 'This may be a new test. If this is an unexpected result, check ' diff --git a/packages/flutter_goldens/test/flutter_goldens_test.dart b/packages/flutter_goldens/test/flutter_goldens_test.dart index 24af462cb1..16fad995fe 100644 --- a/packages/flutter_goldens/test/flutter_goldens_test.dart +++ b/packages/flutter_goldens/test/flutter_goldens_test.dart @@ -903,6 +903,8 @@ void main() { when(mockSkiaClient.getExpectationForTest('flutter.golden_test.1')) .thenAnswer((_) => Future.value('55109a4bed52acc780530f7a9aeff6c0')); + when(mockSkiaClient.getExpectationForTest('flutter.new_golden_test.2')) + .thenAnswer((_) => Future.value('')); when(mockSkiaClient.getImageBytes('55109a4bed52acc780530f7a9aeff6c0')) .thenAnswer((_) => Future>.value(_kTestPngBytes)); when(mockSkiaClient.cleanTestName('library.flutter.golden_test.1.png')) @@ -919,7 +921,7 @@ void main() { ); }); - testWithOutput('passes non-existent baseline for new test', () async { + testWithOutput('passes non-existent baseline for new test, null expectation', () async { expect( await comparator.compare( Uint8List.fromList(_kFailPngBytes), @@ -932,6 +934,19 @@ void main() { 'Validate image output found at flutter/test/library/' ); + testWithOutput('passes non-existent baseline for new test, empty expectation', () async { + expect( + await comparator.compare( + Uint8List.fromList(_kFailPngBytes), + Uri.parse('flutter.new_golden_test.2'), + ), + isTrue, + ); + }, 'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.2. ' + 'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n' + 'Validate image output found at flutter/test/library/' + ); + test('compare properly awaits validation & output before failing.', () async { final Completer completer = Completer(); final Future result = comparator.compare(