sendTestTextOutput method

void sendTestTextOutput(
  1. Map<String, Object?> testNotification
)

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?;
      final messageType = testNotification['messageType'] as String?;

      // Don't send output for print messages that are skip reasons as a
      // result of running with `solo: true` / @soloTest because for suites
      // with many tests, this will bury the useful information in the debug
      // console between lots of repeated skip messages.
      //
      // The JSON messages will have still been forwarded, so the tests can
      // still show up as skipped in the UI, etc.
      const soloSkipMessage = 'Skip: does not have "solo"';
      if (messageType == 'skip' && message == soloSkipMessage) {
        break;
      }

      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;
  }
}