Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#377): list failing tests #397

Merged
merged 7 commits into from
May 20, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/src/cli/flutter_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Flutter {
],
stdout: stdout ?? noop,
stderr: stderr ?? noop,
optimizePerformance: optimizePerformance,
).whenComplete(() {
if (optimizePerformance) {
File(p.join(cwd, 'test', '.test_runner.dart')).delete().ignore();
Expand Down Expand Up @@ -270,21 +271,22 @@ Future<int> _flutterTest({
List<String>? arguments,
required void Function(String) stdout,
required void Function(String) stderr,
required bool optimizePerformance,
renancaraujo marked this conversation as resolved.
Show resolved Hide resolved
}) {
const clearLine = '\u001B[2K\r';

final completer = Completer<int>();
final suites = <int, TestSuite>{};
final groups = <int, TestGroup>{};
final tests = <int, Test>{};
final failedTests = <int>[];

var successCount = 0;
var skipCount = 0;
var failureCount = 0;

String computeStats() {
final passingTests = successCount.formatSuccess();
final failingTests = failureCount.formatFailure();
final failingTests = failedTests.length.formatFailure();
final skippedTests = skipCount.formatSkipped();
final result = [passingTests, failingTests, skippedTests]
..removeWhere((element) => element.isEmpty);
Expand Down Expand Up @@ -347,7 +349,7 @@ Future<int> _flutterTest({
successCount++;
} else {
stderr('$clearLine${test.name} ${suite.path} (FAILED)');
failureCount++;
failedTests.add(test.id);
}

final timeElapsed = Duration(milliseconds: event.time).formatted();
Expand All @@ -366,6 +368,29 @@ Future<int> _flutterTest({
: lightRed.wrap('Some tests failed.')!;

stdout('$clearLine${darkGray.wrap(timeElapsed)} $stats: $summary\n');

if (event.success != true) {
assert(
failedTests.isNotEmpty,
'Invalid state: test event report as faield but no failed tests '
'were gathered',
);
final title = styleBold.wrap('Failing Tests:');
final lines = failedTests.fold<StringBuffer>(
StringBuffer('$clearLine$title\n'),
(previousValue, testId) {
final test = tests[testId];
if (test != null) {
final suitePath = suites[test.suiteID]?.path ?? '';
previousValue.writeln(
'$clearLine - $suitePath:${test.line}:${test.column}',
);
}
return previousValue;
},
);
stderr(lines.toString());
}
}

if (event is ExitTestEvent) {
Expand Down