Skip printing rendered error text in machine mode (#61684)

This commit is contained in:
Helin Shiah
2020-07-20 09:41:03 -07:00
committed by GitHub
parent c4bfa4c7ab
commit 5b9ce492f3
9 changed files with 106 additions and 27 deletions

View File

@@ -3,9 +3,14 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:process/process.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import '../src/common.dart';
import 'test_data/project_with_early_error.dart';
@@ -29,38 +34,89 @@ void main() {
tryToDelete(tempDir);
});
test('flutter run reports an early error in an application', () async {
test('flutter run in non-machine mode reports an early error in an application', () async {
final String flutterBin = globals.fs.path.join(
getFlutterRoot(),
'bin',
'flutter',
);
final StringBuffer stdout = StringBuffer();
await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true);
final Process process = await const LocalProcessManager().start(<String>[
flutterBin,
'run',
'--disable-service-auth-codes',
'--show-test-device',
'-dflutter-tester',
'--start-paused',
'--dart-define=flutter.inspector.structuredErrors=true',
], workingDirectory: tempDir.path);
transformToLines(process.stdout).listen((String line) async {
stdout.writeln(line);
if (line.startsWith('An Observatory debugger')) {
final RegExp exp = RegExp(r'http://127.0.0.1:(\d+)/');
final RegExpMatch match = exp.firstMatch(line);
final String port = match.group(1);
if (port != null) {
final VmService vmService =
await vmServiceConnectUri('ws://localhost:$port/ws');
final VM vm = await vmService.getVM();
for (final IsolateRef isolate in vm.isolates) {
await vmService.resume(isolate.id);
}
}
}
if (line.startsWith('Another exception was thrown')) {
process.kill();
}
});
await process.exitCode;
expect(stdout.toString(), contains(_exceptionStart));
});
test('flutter run in machine mode does not print an error', () async {
final StringBuffer stdout = StringBuffer();
await _flutter.run(
startPaused: true,
withDebugger: true,
structuredErrors: true,
);
await _flutter.resume();
final Completer<void> completer = Completer<void>();
bool lineFound = false;
await Future<void>(() async {
_flutter.stdout.listen((String line) {
stdout.writeln(line);
if (line.startsWith('Another exception was thrown') && !lineFound) {
lineFound = true;
completer.complete();
}
});
await completer.future;
}).timeout(const Duration(seconds: 15), onTimeout: () {
// Complete anyway in case we don't see the 'Another exception' line.
}).timeout(const Duration(seconds: 5), onTimeout: () {
// We don't expect to see any output but want to write to stdout anyway.
completer.complete();
});
await _flutter.stop();
expect(stdout.toString(), contains(_exceptionStart));
expect(stdout.toString(), isNot(contains(_exceptionStart)));
});
test('flutter run for web reports an early error in an application', () async {
final StringBuffer stdout = StringBuffer();
await _flutter.run(startPaused: true, withDebugger: true, structuredErrors: true, chrome: true);
await _flutter.run(
startPaused: true,
withDebugger: true,
structuredErrors: true,
chrome: true,
machine: false,
);
await _flutter.resume();
final Completer<void> completer = Completer<void>();

View File

@@ -439,6 +439,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool chrome = false,
bool expressionEvaluation = true,
bool structuredErrors = false,
bool machine = true,
File pidFile,
String script,
}) async {
@@ -447,7 +448,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
'run',
if (!chrome)
'--disable-service-auth-codes',
'--machine',
if (machine) '--machine',
'-d',
if (chrome)
...<String>[