diff --git a/packages/flutter_goldens/lib/flutter_goldens.dart b/packages/flutter_goldens/lib/flutter_goldens.dart index 6641414875..e0b5bdfcc2 100644 --- a/packages/flutter_goldens/lib/flutter_goldens.dart +++ b/packages/flutter_goldens/lib/flutter_goldens.dart @@ -167,6 +167,12 @@ abstract class FlutterGoldenFileComparator extends GoldenFileComparator { /// Prepends the golden URL with the library name that encloses the current /// test. Uri _addPrefix(Uri golden) { + // Ensure the Uri ends in .png as the SkiaClient expects + assert( + golden.toString().split('.').last == 'png', + 'Golden files in the Flutter framework must end with the file extension ' + '.png.' + ); final String prefix = basedir.pathSegments[basedir.pathSegments.length - 2]; return Uri.parse('$prefix.$golden'); } diff --git a/packages/flutter_goldens/test/flutter_goldens_test.dart b/packages/flutter_goldens/test/flutter_goldens_test.dart index c5d22cc5f7..494f582cfe 100644 --- a/packages/flutter_goldens/test/flutter_goldens_test.dart +++ b/packages/flutter_goldens/test/flutter_goldens_test.dart @@ -481,6 +481,26 @@ void main() { ); }); + test('asserts .png format', () async { + await expectLater( + () async { + return comparator.compare( + Uint8List.fromList(_kTestPngBytes), + Uri.parse('flutter.golden_test.1'), + ); + }, + throwsA( + isA().having((AssertionError error) => error.toString(), + 'description', + contains( + 'Golden files in the Flutter framework must end with the file ' + 'extension .png.' + ), + ), + ), + ); + }); + test('calls init during compare', () { expect(fakeSkiaClient.initCalls, 0); comparator.compare( @@ -579,6 +599,26 @@ void main() { ); }); + test('asserts .png format', () async { + await expectLater( + () async { + return comparator.compare( + Uint8List.fromList(_kTestPngBytes), + Uri.parse('flutter.golden_test.1'), + ); + }, + throwsA( + isA().having((AssertionError error) => error.toString(), + 'description', + contains( + 'Golden files in the Flutter framework must end with the file ' + 'extension .png.' + ), + ), + ), + ); + }); + test('calls init during compare', () { expect(fakeSkiaClient.tryInitCalls, 0); comparator.compare( @@ -745,6 +785,26 @@ void main() { fakeSkiaClient.cleanTestNameValues['library.flutter.golden_test.1.png'] = 'flutter.golden_test.1'; }); + test('asserts .png format', () async { + await expectLater( + () async { + return comparator.compare( + Uint8List.fromList(_kTestPngBytes), + Uri.parse('flutter.golden_test.1'), + ); + }, + throwsA( + isA().having((AssertionError error) => error.toString(), + 'description', + contains( + 'Golden files in the Flutter framework must end with the file ' + 'extension .png.' + ), + ), + ), + ); + }); + test('passes when bytes match', () async { expect( await comparator.compare(