test: automated golden tests

Any riv added to `test/assets/batch_rive` will automatically be tested. The test includes:
1. Setting up the animation to play the default state machine
2. Render first frame
3. Advance by three quarters of a second
4. Advance by two seconds

Diffs=
7c3f77dd6 test: automated golden tests (#5785)

Co-authored-by: Gordon <pggordonhayes@gmail.com>
This commit is contained in:
HayesGordon
2023-08-10 15:13:47 +00:00
parent 1da10ef040
commit 7cb217b980
23 changed files with 166 additions and 1 deletions

View File

@ -1 +1 @@
b905380c98465d91ad080e078be1a8390a09b788
7c3f77dd60c74a7bbd376ed9e9e43fcdec898d8f

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:249baa6c8e69991c3d563e01942fa8e14d586f5325af81d7bbf2fae86de2a630
size 286936

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5aa95fe11dad1d78882d1537a61e175d8a1777efcb06b62310818aa203d4c177
size 18519

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:560d6f4bdf39b83196fd49e4e8a1825b05279a83801cba80384640e1e1a6427a
size 10715

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:72ddd483375fa9f38d47b765b9a4b3a3c4ea1568f175dce13c5cf0a95ef31bbe
size 7248

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:76e792dac0d5900841d0ed4112882725923173ea085bfe0471c74f9fdbf9f414
size 7709

View File

@ -0,0 +1,72 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:rive/rive.dart';
import '../../src/utils.dart';
import '../golden_comparator.dart';
void main() {
/// Tests all rivs in the `test/assets/batch_rive` directory
group('Golden - Batch tests riv files', () {
List<FileTesterWrapper> riveFiles = [];
setUpAll(() {
// Read all files in the batch directory to be tested.
riveFiles = batchRiveFilesToTest();
});
testWidgets('Animation default state machine render as expected',
(WidgetTester tester) async {
for (final file in riveFiles) {
final riveFile =
RiveFile.import(ByteData.sublistView(file.file.readAsBytesSync()));
final fileName = file.fileName;
late Artboard artboard;
// TODO: change this once the default behavior is to play
// the default state machine. Adding this for now as it ensures we
// do not have to update tests when the default behavior changes.
final defaultStateMachineName =
riveFile.mainArtboard.defaultStateMachine?.name ??
riveFile.mainArtboard.stateMachines.first.name;
await tester.pumpWidget(
RiveAnimation.direct(
riveFile,
stateMachines: [defaultStateMachineName],
onInit: (a) {
artboard = a;
},
),
);
// Render first frame of animation
await tester.pump();
await expectGoldenMatches(
find.byType(RiveAnimation),
'$fileName-01.png',
reason: 'Animation with filename: $fileName should render correctly',
);
// Advance animation by a three quarters of a second
artboard.advance(0.75, nested: true);
await tester.pump();
await expectGoldenMatches(
find.byType(RiveAnimation),
'$fileName-02.png',
reason: 'Animation with filename: $fileName should render correctly',
);
// Advance animation by a two seconds
artboard.advance(2, nested: true);
await tester.pump();
await expectGoldenMatches(
find.byType(RiveAnimation),
'$fileName-03.png',
reason: 'Animation with filename: $fileName should render correctly',
);
}
});
});
}

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9b4712208425ed76c18ecdd18faf492f73f91e9719c067bc30af5e3b6e6e2220
size 243641

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:449c14a593c2240e47ac15e3a77ac584002a8bf781b655bc08511ef1567c7393
size 248036

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f3001e99269181d0d0cdde039648bcf29c306796902c2045f484ed75f334a37b
size 255681

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c200eec04e171aa5b8be4da0bec300bf8ab60845ca790eb15fce17bff7b49f1a
size 65619

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f5f7e1edba94cf923cff8cbf83ac9a9f4de017e9b796b064f6aca4ad7464e052
size 65749

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f17964c69d0f4ca259483f6bad3e67fc9ab032724f629bfa15a54e77cd79a353
size 64755

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2269ee9c7aacf01e6f178a66e3845a74bcee15324ef9d39877f3966e0c5dd9a3
size 52995

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7baa2fb18c5c8460b391cf328336a88239179db7bb1ca11fc2d1746085a7249f
size 54195

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:07bc175d641c6cd656cef9e07894e32edcdff4df93a82abb997c8facba335289
size 53069

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7c2ea06d5197e10a4f39e5b558c98ad1e53d2281b4a9b30ff111ac177d731f17
size 30529

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:461fffd2c875b908f23cba85dbfb092d63e8e74fe7b96ea081611e7a21d8316e
size 32964

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c88ecedf4349b93c5b611586b3b2dc01583cd7f0751c9fb385c27c9493c38a7b
size 34297

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9e223398daaca513be2dbe173b6ce12a21886f8322c7b18dd250da0063fb9383
size 60993

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9730839bddf5c32ae29bbcda4406cf8516096e5b430cf2bc0e465e6426f2adb8
size 55110

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b2da2a4183b9972bff47709041a51b6bd34501e8392ed52575f5ca17d90fa684
size 63634

View File

@ -1,9 +1,42 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/widgets.dart';
import 'package:path/path.dart';
/// Loads a Rive file from the assets sub-folder
ByteData loadFile(String filename) {
final file = File(
'./${Directory.current.path.endsWith('/test') ? '' : 'test/'}$filename');
return ByteData.sublistView(file.readAsBytesSync());
}
/// Loads in all the files in the batch_rivs directory ('test/assets/batch_rivs')
List<FileTesterWrapper> batchRiveFilesToTest() {
final directory = Directory('test/assets/batch_rivs');
final files = directory.listSync();
return files.map((e) {
try {
final file = e as File;
return FileTesterWrapper(
file: file,
fileName: basename(file.path),
);
// ignore: avoid_catches_without_on_clauses
} catch (e, st) {
debugPrintStack(stackTrace: st);
throw Exception('Not a Rive file');
}
}).toList();
}
class FileTesterWrapper {
final File file;
final String fileName;
FileTesterWrapper({
required this.file,
required this.fileName,
});
}