sendTestTextOutput method
Sends textual output for tests, including pass/fail and test output.
This is sent so that clients that do not handle the package:test JSON events still get some useful textual output in their Debug Consoles.
Implementation
void sendTestTextOutput(Map<String, Object?> testNotification) {
switch (testNotification['type']) {
case 'testStart':
// When a test starts, capture its name by ID so we can get it back when
// testDone comes.
final test = testNotification['test'] as Map<String, Object?>?;
if (test != null) {
final testID = test['id'] as int?;
final testName = test['name'] as String?;
if (testID != null && testName != null) {
_testNames[testID] = testName;
}
}
break;
case 'testDone':
// Print the status of completed tests with a tick/cross.
if (testNotification['hidden'] == true) {
break;
}
final testID = testNotification['testID'] as int?;
if (testID != null) {
final testName = _testNames[testID];
if (testName != null) {
final symbol = testNotification['skipped'] == true
? _skippedSymbol
: testNotification['result'] == "success"
? _passSymbol
: _failSymbol;
sendOutput('console', '$symbol $testName\n');
}
}
break;
case 'print':
final message = testNotification['message'] as String?;
if (message != null) {
sendOutput('stdout', '${message.trimRight()}\n');
}
break;
case 'error':
final error = testNotification['error'] as String?;
final stack = testNotification['stackTrace'] as String?;
if (error != null) {
sendOutput('stderr', '${error.trimRight()}\n');
}
if (stack != null) {
sendOutput('stderr', '${stack.trimRight()}\n');
}
break;
}
}