wrapWithPatrolLog<T> method
Wraps a function with a log entry for the start and end of the function.
Implementation
Future<T> wrapWithPatrolLog<T>({
required String action,
String? value,
required String color,
required Future<T> Function() function,
bool enablePatrolLog = true,
}) async {
if (!(tester.config.printLogs && enablePatrolLog)) {
return function();
}
final finderText = finder
.toString(describeSelf: true)
.replaceAll('A finder that searches for', '')
.replaceAll(' (considering only hit-testable ones)', '')
.replaceAll(' (ignoring all but first)', '');
final valueText = value != null ? ' "$value"' : '';
final text = '$color$action${AnsiCodes.reset}$valueText$finderText';
tester.patrolLog.log(
StepEntry(action: text, status: StepEntryStatus.start),
);
try {
final result = await function();
tester.patrolLog.log(
StepEntry(action: text, status: StepEntryStatus.success),
);
return result;
} catch (err) {
tester.patrolLog.log(
StepEntry(action: text, status: StepEntryStatus.failure),
);
rethrow;
}
}