Skip to content

Commit 4adfec7

Browse files
committed
fix(test): truncate output to fit line
1 parent c6e4ae4 commit 4adfec7

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

lib/src/cli/flutter_cli.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Future<void> _flutterTest({
142142
},
143143
);
144144

145-
flutterTest(workingDirectory: cwd).listen(
145+
flutterTest(workingDirectory: cwd, runInShell: true).listen(
146146
(event) {
147147
if (event.shouldCancelTimer()) timerSubscription.cancel();
148148
if (event is SuiteTestEvent) suites[event.suite.id] = event.suite;
@@ -184,7 +184,8 @@ Future<void> _flutterTest({
184184

185185
final timeElapsed = Duration(milliseconds: event.time).formatted();
186186
final stats = computeStats();
187-
stdout('$clearLine$timeElapsed $stats: ${test.name}');
187+
final testName = test.name.truncated(_lineLength - 15);
188+
stdout('''$clearLine$timeElapsed $stats: $testName''');
188189
}
189190

190191
if (event is DoneTestEvent) {
@@ -204,6 +205,14 @@ Future<void> _flutterTest({
204205
return completer.future;
205206
}
206207

208+
final int _lineLength = () {
209+
try {
210+
return stdout.terminalColumns;
211+
} on StdoutException {
212+
return 80;
213+
}
214+
}();
215+
207216
extension on TestEvent {
208217
bool shouldCancelTimer() {
209218
final event = this;
@@ -237,3 +246,11 @@ extension on int {
237246
return this > 0 ? lightYellow.wrap('~$this')! : '';
238247
}
239248
}
249+
250+
extension on String {
251+
String truncated(int maxLength) {
252+
if (length <= maxLength) return this;
253+
final truncated = trim().substring(length - maxLength, length);
254+
return '...$truncated';
255+
}
256+
}

test/src/cli/flutter_cli_test.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ void main() {
242242
verify(
243243
() => logger.err(any(that: contains('${testFile.path} (FAILED)'))),
244244
).called(1);
245+
verify(
246+
() => logger.write(any(that: contains('-1: example'))),
247+
).called(1);
245248
verify(
246249
() => logger.write(any(that: contains('Some tests failed.'))),
247250
).called(1);
@@ -272,7 +275,10 @@ void main() {
272275
() => logger.write(any(that: contains('${testFile.path} (SKIPPED)'))),
273276
).called(1);
274277
verify(
275-
() => logger.write(any(that: contains('All tests passed!'))),
278+
() => logger.write(any(that: contains('+1 ~1: example'))),
279+
).called(1);
280+
verify(
281+
() => logger.write(any(that: contains('+1 ~1: All tests passed!'))),
276282
).called(1);
277283
});
278284

@@ -309,7 +315,10 @@ void main() {
309315
() => logger.write(any(that: contains('${testFile.path} (SKIPPED)'))),
310316
).called(1);
311317
verify(
312-
() => logger.write(any(that: contains('All tests passed!'))),
318+
() => logger.write(any(that: contains('+1 ~1: example'))),
319+
).called(1);
320+
verify(
321+
() => logger.write(any(that: contains('+1 ~1: All tests passed!'))),
313322
).called(1);
314323
});
315324

@@ -338,7 +347,10 @@ void main() {
338347
() => logger.write(any(that: contains('Hello World'))),
339348
).called(1);
340349
verify(
341-
() => logger.write(any(that: contains('All tests passed!'))),
350+
() => logger.write(any(that: contains('+1: example'))),
351+
).called(1);
352+
verify(
353+
() => logger.write(any(that: contains('+1: All tests passed!'))),
342354
).called(1);
343355
});
344356

@@ -368,7 +380,10 @@ void main() {
368380
() => logger.err(any(that: contains('Exception: oops'))),
369381
).called(1);
370382
verify(
371-
() => logger.write(any(that: contains('Some tests failed.'))),
383+
() => logger.write(any(that: contains('-1: example'))),
384+
).called(1);
385+
verify(
386+
() => logger.write(any(that: contains('-1: Some tests failed.'))),
372387
).called(1);
373388
});
374389

@@ -405,7 +420,7 @@ void main() {
405420
),
406421
).called(1);
407422
verify(
408-
() => logger.write(any(that: contains('All tests passed!'))),
423+
() => logger.write(any(that: contains('+1: All tests passed!'))),
409424
).called(1);
410425
});
411426

@@ -440,7 +455,7 @@ void main() {
440455
),
441456
).called(1);
442457
verify(
443-
() => logger.write(any(that: contains('All tests passed!'))),
458+
() => logger.write(any(that: contains('+1: All tests passed!'))),
444459
).called(1);
445460
});
446461
});

0 commit comments

Comments
 (0)