readEntries method
Read the entries from the stream and print them to the console.
Implementation
Future<void> readEntries() async {
var stepsCounter = 0;
var logsCounter = 0;
_streamSubscription = _controller.stream.listen((entry) {
switch (entry) {
case TestEntry()
when entry.status == TestEntryStatus.skip ||
entry.status == TestEntryStatus.start:
// Create a new single test entry for the test that is starting or is skipped.
final singleEntry = PatrolSingleTestEntry(entry);
_singleEntries.add(singleEntry);
if (entry.status == TestEntryStatus.start) {
final normalizedTestName = _normalizeTestName(entry.name);
_openEntriesByName
.putIfAbsent(normalizedTestName, () => [])
.add(singleEntry);
}
// Print the test entry to the console.
if (!hideTestLifecycle) {
log(entry.pretty());
}
// Reset the counters needed for clearing the lines.
stepsCounter = 0;
logsCounter = 0;
case TestEntry():
// Close the matching test entry by name.
final singleEntry = _takeOpenSingleEntry(entry.name);
singleEntry?.closeTest(entry);
// Optionally clear all printed [StepEntry] and [LogEntry].
if (!showFlutterLogs &&
clearTestSteps &&
entry.status != TestEntryStatus.failure) {
// +1 for the test-start line, but only if it was actually printed.
final lifecycleLine = hideTestLifecycle ? 0 : 1;
_clearLines(stepsCounter + logsCounter + lifecycleLine);
}
final executionTime = singleEntry?.executionTime.inSeconds;
// Print test entry summary to console.
if (!hideTestLifecycle) {
log(
'${entry.pretty()} '
'${executionTime != null ? '${AnsiCodes.gray}(${executionTime}s)${AnsiCodes.reset}' : ''}',
);
}
case StepEntry():
_singleEntries.last.addEntry(entry);
if (!hideTestSteps) {
// Clear the previous line it's not the new step, or increment counter
// for new step
if (entry.status == StepEntryStatus.start) {
stepsCounter++;
} else if (clearTestSteps) {
_clearPreviousLine();
}
// Print the step entry to the console.
log(entry.pretty(number: stepsCounter));
}
case LogEntry():
_singleEntries.last.addEntry(entry);
logsCounter++;
// Print the log entry to the console.
log(entry.pretty());
case ErrorEntry():
case WarningEntry():
log(entry.pretty());
case ConfigEntry():
_readConfig(entry);
}
});
}