printTestInfo method

void printTestInfo(
  1. Iterable jsons
)

Implementation

void printTestInfo(Iterable<dynamic> jsons) {
  try {
    var eventDone =
        jsons.whereType<Map>().lastWhere((e) => e['type'] == 'done');
    var testsDone =
        jsons.whereType<Map>().where((e) => e['type'] == 'testDone').toList();

    var testsSkipped = testsDone
        .whereType<Map>()
        .where((e) => e['skipped'] == true)
        .toList();

    var testsNotSkipped =
        testsDone.where((e) => e['skipped'] != true).toList();

    var testsSuccess =
        testsNotSkipped.where((e) => e['result'] == 'success').toList();

    var testsFail =
        testsNotSkipped.where((e) => e['result'] == 'failure').toList();

    var sucess = eventDone['success'] as bool;
    var timeMs = eventDone['time'] as int;
    var time = Duration(milliseconds: timeMs);

    var testsInfo = [
      if (testsSuccess.isNotEmpty) '+${testsSuccess.length}',
      if (testsSkipped.isNotEmpty) '~${testsSkipped.length}',
      if (testsFail.isNotEmpty) '-${testsFail.length}',
    ];

    var testsInfoLine = testsInfo.isNotEmpty ? ' ${testsInfo.join(' ')}' : '';

    printBox([
      'Tests:$testsInfoLine',
      '» Sucess: $sucess',
      '» Time: ${time.inSeconds} sec',
    ]);
  } catch (e) {
    print('** Error processing test events: $e');
  }
}