testWriter method

Future<bool> testWriter(
  1. BuildContext context,
  2. Test test
)

When running on a non-web platform this will write the test to the file system using the testPath.

Implementation

Future<bool> testWriter(
  BuildContext context,
  Test test,
) async {
  var result = false;
  if (kIsWeb) {
    _logger.warning(
      '[IoTestStore] -- testReader not supported on web',
    );
  } else {
    var path = testPath;

    if (test.suiteName != null) {
      path = '${path}/${test.suiteName}_';
    } else {
      path = '$path/';
    }

    path = '$path${test.name}.json';

    var encoder = JsonEncoder.withIndent('  ');
    var file = File(path);

    file.createSync(recursive: true);

    var testData = test
        .copyWith(
          steps: test.steps
              .map((e) => e.copyWith(image: Uint8List.fromList([])))
              .toList(),
          timestamp: DateTime.now(),
          version: test.version,
        )
        .toJson();

    file.writeAsStringSync(encoder.convert(testData));
    _logger.info('[REPORT]: ${file.absolute.path}');
  }
  return result;
}