-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: golden tests don't work with test optimisation flag #363
Comments
Hey @wolfenrain, the problem is that the Now when you use the test optimization, all tests are executed from I found a pretty nifty workaround to fix this: when running with test optimization, change the implementation of import 'dart:io';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
// ... imports of all tests ...
class _TestOptimizationAwareGoldenFileComparator extends LocalFileComparator {
final List<String> goldenFiles;
_TestOptimizationAwareGoldenFileComparator()
: goldenFiles = Directory.fromUri(
(goldenFileComparator as LocalFileComparator).basedir)
.listSync(recursive: true, followLinks: true)
.whereType<File>()
.map((file) => file.path)
.where((path) => path.endsWith('.png'))
.toList(),
super(_getTestFile());
static Uri _getTestFile() {
final basedir =
(goldenFileComparator as LocalFileComparator).basedir.toString();
return Uri.parse("$basedir/.test_runner.dart");
}
@override
Uri getTestUri(Uri key, int? version) {
final keyString = fromUri(key);
return Uri.parse(goldenFiles
.singleWhere((goldenFilePath) => goldenFilePath.endsWith(keyString)));
}
}
void main(){
goldenFileComparator = _TestOptimizationAwareGoldenFileComparator();
// ... execution of all tests ..
} |
Thanks for taking the time to investigate and for sharing your solution! We'll try to address this soon 👍 |
This got accidentally closed, reopening it as a few changes are still needed. |
Description
Testing goldens don't work when using the test optimisation. It throws an error, only work around at the moment is not using optimisation.
Steps To Reproduce
very_good test --update-goldens
very_good test --optimization
Expected Behavior
That I can run my golden tests while utilising test optimisation.
Additional Context
The text was updated successfully, but these errors were encountered: