Skip to content

Commit

Permalink
fix: fix test report in case of multiline test name (#535)
Browse files Browse the repository at this point in the history
Co-authored-by: Abdelaziz GACEMI <agacemi@oui.sncf>
Co-authored-by: Renan <6718144+renancaraujo@users.noreply.github.com>
Co-authored-by: Felix Angelov <felangelov@gmail.com>
  • Loading branch information
4 people committed Jan 23, 2023
1 parent 560f44a commit 5f2aa49
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/src/cli/flutter_cli.dart
Expand Up @@ -398,9 +398,9 @@ Future<int> _flutterTest({

final timeElapsed = Duration(milliseconds: event.time).formatted();
final stats = computeStats();
final testName = test.name.truncated(
_lineLength - (timeElapsed.length + stats.length + 2),
);
final testName = test.name.toSingleLine().truncated(
_lineLength - (timeElapsed.length + stats.length + 2),
);
stdout('''$clearLine$timeElapsed $stats: $testName''');
}

Expand Down Expand Up @@ -496,6 +496,9 @@ extension on String {
final truncated = substring(length - maxLength, length).trim();
return '...$truncated';
}

String toSingleLine() =>
replaceAll('\n', '').replaceAll(RegExp(r'\s\s+'), ' ');
}

String? _getTraceLocation({
Expand Down
40 changes: 39 additions & 1 deletion test/fixtures/test_runner_fixtures.dart
Expand Up @@ -1120,6 +1120,21 @@ const skipExceptionMessageJsonOuput = [
'type': 'testStart',
'time': 2757
},
{
'test': {
'id': 29,
'name': '''this is the case of a multiline test name that should '''
''' be well processed by very_good test ''',
'suiteID': 4,
'groupIDs': [16],
'metadata': {'skip': false, 'skipReason': null},
'line': 4,
'column': 3,
'url': 'file:///my_app/test/counter/view/long_name_test.dart'
},
'type': 'testStart',
'time': 2757
},
{
'testID': 15,
'result': 'success',
Expand Down Expand Up @@ -1401,5 +1416,28 @@ const skipExceptionMessageJsonOuput = [
'type': 'testDone',
'time': 4248
},
{'success': false, 'type': 'done', 'time': 4266},
{
'test': {
'id': 29,
'name': '''this is the case of a multiline test name that should '''
''' be well processed by very_good test ''',
'suiteID': 4,
'groupIDs': [16],
'metadata': {'skip': false, 'skipReason': null},
'line': 4,
'column': 3,
'url': 'file:///my_app/test/counter/view/multiline_test.dart'
},
'type': 'testStart',
'time': 5440
},
{
'testID': 29,
'result': 'success',
'skipped': false,
'hidden': false,
'type': 'testDone',
'time': 5449
},
{'success': false, 'type': 'done', 'time': 5466},
];
3 changes: 2 additions & 1 deletion test/src/cli/flutter_cli_test.dart
Expand Up @@ -503,7 +503,8 @@ void main() {
'\x1B[2K\r00:04 +5 -1 ~2: CounterView renders current count',
'''\x1B[2K\r00:04 +6 -1 ~2: CounterView calls increment when increment button is tapped''',
'''\x1B[2K\r00:04 +7 -1 ~2: CounterView calls decrement when decrement button is tapped''',
'\x1B[2K\r00:04 +7 -1 ~2: Some tests failed.\n'
'''\x1B[2K\r00:05 +8 -1 ~2: ...tiline test name that should be well processed by very_good test''',
'\x1B[2K\r00:05 +8 -1 ~2: Some tests failed.\n'
]),
);
expect(
Expand Down

0 comments on commit 5f2aa49

Please sign in to comment.