Fix stack trace parsing on non-debug builds; add e2e tests (#50652)
* Fix stack trace parsing on non-debug builds; add e2e tests
This commit is contained in:
59
dev/bots/browser.dart
Normal file
59
dev/bots/browser.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
import 'package:shelf/shelf_io.dart' as shelf_io;
|
||||
import 'package:shelf_static/shelf_static.dart';
|
||||
|
||||
import 'package:flutter_devicelab/framework/browser.dart';
|
||||
|
||||
/// Runs Chrome, opens the given `appUrl`, and returns the result reported by the
|
||||
/// app.
|
||||
///
|
||||
/// The app is served from the `appDirectory`. Typically, the app is built
|
||||
/// using `flutter build web` and served from `build/web`.
|
||||
///
|
||||
/// The launched app is expected to report the result by sending an HTTP POST
|
||||
/// request to "/test-result" containing result data as plain text body of the
|
||||
/// request. This function has no opinion about what that string contains.
|
||||
Future<String> evalTestAppInChrome({
|
||||
@required String appUrl,
|
||||
@required String appDirectory,
|
||||
int serverPort = 8080,
|
||||
int browserDebugPort = 8081,
|
||||
}) async {
|
||||
io.HttpServer server;
|
||||
Chrome chrome;
|
||||
try {
|
||||
final Completer<String> resultCompleter = Completer<String>();
|
||||
server = await io.HttpServer.bind('localhost', serverPort);
|
||||
final Cascade cascade = Cascade()
|
||||
.add((Request request) async {
|
||||
if (request.requestedUri.path.endsWith('/test-result')) {
|
||||
resultCompleter.complete(await request.readAsString());
|
||||
return Response.ok('Test results received');
|
||||
}
|
||||
return Response.notFound('');
|
||||
})
|
||||
.add(createStaticHandler(appDirectory));
|
||||
shelf_io.serveRequests(server, cascade.handler);
|
||||
final io.Directory userDataDirectory = io.Directory.systemTemp.createTempSync('chrome_user_data_');
|
||||
chrome = await Chrome.launch(ChromeOptions(
|
||||
headless: true,
|
||||
debugPort: browserDebugPort,
|
||||
url: appUrl,
|
||||
userDataDirectory: userDataDirectory.path,
|
||||
windowHeight: 500,
|
||||
windowWidth: 500,
|
||||
), onError: resultCompleter.completeError);
|
||||
return await resultCompleter.future;
|
||||
} finally {
|
||||
chrome?.stop();
|
||||
await server?.close();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ environment:
|
||||
dependencies:
|
||||
args: 1.5.2
|
||||
crypto: 2.1.3
|
||||
flutter_devicelab:
|
||||
path: ../devicelab
|
||||
googleapis: 0.54.0
|
||||
googleapis_auth: 0.2.11+1
|
||||
http: 0.12.0+4
|
||||
|
||||
@@ -53,6 +53,15 @@ Stream<String> runAndGetStdout(String executable, List<String> arguments, {
|
||||
print('$clock ELAPSED TIME: ${prettyPrintDuration(time.elapsed)} for $green$commandDescription$reset in $cyan$relativeWorkingDir$reset');
|
||||
}
|
||||
|
||||
/// Runs the `executable` and waits until the process exits.
|
||||
///
|
||||
/// If the process exits with a non-zero exit code, exits this process with
|
||||
/// exit code 1, unless `expectNonZeroExit` is set to true.
|
||||
///
|
||||
/// `outputListener` is called for every line of standard output from the
|
||||
/// process, and is given the [Process] object. This can be used to interrupt
|
||||
/// an indefinitely running process, for example, by waiting until the process
|
||||
/// emits certain output.
|
||||
Future<void> runCommand(String executable, List<String> arguments, {
|
||||
String workingDirectory,
|
||||
Map<String, String> environment,
|
||||
@@ -63,6 +72,7 @@ Future<void> runCommand(String executable, List<String> arguments, {
|
||||
CapturedOutput output,
|
||||
bool skip = false,
|
||||
bool Function(String) removeLine,
|
||||
void Function(String, Process) outputListener,
|
||||
}) async {
|
||||
assert(
|
||||
(outputMode == OutputMode.capture) == (output != null),
|
||||
@@ -88,7 +98,13 @@ Future<void> runCommand(String executable, List<String> arguments, {
|
||||
.transform<String>(const Utf8Decoder())
|
||||
.transform(const LineSplitter())
|
||||
.where((String line) => removeLine == null || !removeLine(line))
|
||||
.map((String line) => '$line\n')
|
||||
.map((String line) {
|
||||
final String formattedLine = '$line\n';
|
||||
if (outputListener != null) {
|
||||
outputListener(formattedLine, process);
|
||||
}
|
||||
return formattedLine;
|
||||
})
|
||||
.transform(const Utf8Encoder());
|
||||
switch (outputMode) {
|
||||
case OutputMode.print:
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:googleapis_auth/auth_io.dart' as auth;
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'browser.dart';
|
||||
import 'flutter_compact_formatter.dart';
|
||||
import 'run_command.dart';
|
||||
import 'utils.dart';
|
||||
@@ -116,7 +117,8 @@ Future<void> main(List<String> args) async {
|
||||
'hostonly_devicelab_tests': _runHostOnlyDeviceLabTests,
|
||||
'tool_coverage': _runToolCoverage,
|
||||
'tool_tests': _runToolTests,
|
||||
'web_tests': _runWebTests,
|
||||
'web_tests': _runWebUnitTests,
|
||||
'web_integration_tests': _runWebIntegrationTests,
|
||||
});
|
||||
} on ExitException catch (error) {
|
||||
error.apply();
|
||||
@@ -522,7 +524,7 @@ Future<void> _runFrameworkCoverage() async {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _runWebTests() async {
|
||||
Future<void> _runWebUnitTests() async {
|
||||
final Map<String, ShardRunner> subshards = <String, ShardRunner>{};
|
||||
|
||||
final Directory flutterPackageDirectory = Directory(path.join(flutterRoot, 'packages', 'flutter'));
|
||||
@@ -585,6 +587,94 @@ Future<void> _runWebTests() async {
|
||||
await selectSubshard(subshards);
|
||||
}
|
||||
|
||||
Future<void> _runWebIntegrationTests() async {
|
||||
await _runWebStackTraceTest('profile');
|
||||
await _runWebStackTraceTest('release');
|
||||
await _runWebDebugStackTraceTest();
|
||||
}
|
||||
|
||||
Future<void> _runWebStackTraceTest(String buildMode) async {
|
||||
final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web');
|
||||
final String appBuildDirectory = path.join('$testAppDirectory', 'build', 'web');
|
||||
|
||||
// Build the app.
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[ 'clean' ],
|
||||
workingDirectory: testAppDirectory,
|
||||
);
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[
|
||||
'build',
|
||||
'web',
|
||||
'--$buildMode',
|
||||
'-t',
|
||||
'lib/stack_trace.dart',
|
||||
],
|
||||
workingDirectory: testAppDirectory,
|
||||
environment: <String, String>{
|
||||
'FLUTTER_WEB': 'true',
|
||||
},
|
||||
);
|
||||
|
||||
// Run the app.
|
||||
final String result = await evalTestAppInChrome(
|
||||
appUrl: 'http://localhost:8080/index.html',
|
||||
appDirectory: appBuildDirectory,
|
||||
);
|
||||
|
||||
if (result.contains('--- TEST SUCCEEDED ---')) {
|
||||
print('${green}Web stack trace integration test passed.$reset');
|
||||
} else {
|
||||
print(result);
|
||||
print('${red}Web stack trace integration test failed.$reset');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Debug mode is special because `flutter build web` doesn't build in debug mode.
|
||||
///
|
||||
/// Instead, we use `flutter run --debug` and sniff out the standard output.
|
||||
Future<void> _runWebDebugStackTraceTest() async {
|
||||
final String testAppDirectory = path.join(flutterRoot, 'dev', 'integration_tests', 'web');
|
||||
final CapturedOutput output = CapturedOutput();
|
||||
bool success = false;
|
||||
await runCommand(
|
||||
flutter,
|
||||
<String>[
|
||||
'run',
|
||||
'--debug',
|
||||
'-d',
|
||||
'chrome',
|
||||
'--web-run-headless',
|
||||
'lib/stack_trace.dart',
|
||||
],
|
||||
output: output,
|
||||
outputMode: OutputMode.capture,
|
||||
outputListener: (String line, Process process) {
|
||||
if (line.contains('--- TEST SUCCEEDED ---')) {
|
||||
success = true;
|
||||
}
|
||||
if (success || line.contains('--- TEST FAILED ---')) {
|
||||
process.stdin.add('q'.codeUnits);
|
||||
}
|
||||
},
|
||||
workingDirectory: testAppDirectory,
|
||||
environment: <String, String>{
|
||||
'FLUTTER_WEB': 'true',
|
||||
},
|
||||
);
|
||||
|
||||
if (success) {
|
||||
print('${green}Web stack trace integration test passed.$reset');
|
||||
} else {
|
||||
print(output.stdout);
|
||||
print('${red}Web stack trace integration test failed.$reset');
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _runFlutterWebTest(String workingDirectory, List<String> tests) async {
|
||||
final List<String> batch = <String>[];
|
||||
for (int i = 0; i < tests.length; i += 1) {
|
||||
|
||||
Reference in New Issue
Block a user