testWriter method
Implementation of the TestWriter
functional interface that can submit
test data to GitHub.
Implementation
Future<bool> testWriter(
BuildContext context,
Test test,
) async {
await _loadData();
var result = false;
try {
final actualTestsPath =
testsPath.startsWith('/') ? testsPath.substring(1) : testsPath;
final version = test.version + 1;
final testData = test
.copyWith(
steps: test.steps
.map(
(step) => step.copyWith(
image: Uint8List.fromList(<int>[]),
),
)
.toList(),
timestamp: DateTime.now(),
version: version,
)
.toJson();
final testSuitePrefix =
test.suiteName?.isNotEmpty == true ? '${test.suiteName}/' : '';
final path = '$actualTestsPath/$testSuitePrefix${test.name}.json';
final encoder = const JsonEncoder.withIndent(' ');
await uploadFile(
data: utf8.encode(encoder.convert(testData)),
message: 'Updating test',
path: path,
);
result = true;
} catch (e, stack) {
_logger.severe('Error writing test', e, stack);
}
return result;
}