goldenImageWriter method

Future<void> goldenImageWriter(
  1. TestReport report
)

When running on a non-web platform this will write the golden images from the given report to the file system using the imagePath.

Implementation

Future<void> goldenImageWriter(TestReport report) async {
  if (kIsWeb) {
    _logger.warning(
      '[IoTestStore] -- goldenImageWriter not supported on web',
    );
  } else {
    var path = imagePath;
    if (report.suiteName?.isNotEmpty == true) {
      path = '${path}/_Suite_${report.suiteName}_';
    } else {
      path = '$path/';
    }

    path = '${path}Test_${report.name}_';

    for (var image in report.images) {
      if (image.goldenCompatible) {
        var file = File('${path}${image.id}.png');
        file.createSync(recursive: true);

        var data = image.image!;
        file.writeAsBytesSync(data);

        final testImageCodec = await instantiateImageCodec(data);
        final testImage = (await testImageCodec.getNextFrame()).image;

        _logger.info(
          '[IMAGE]: ${file.absolute.path} -- (${testImage.width}, ${testImage.height})',
        );
      }
    }
  }
}