Make it possible to override the FLUTTER_TEST env variable (#34301)

* Make it possible to override the FLUTTER_TEST env variable without unsetting it.

* Switch to using platform instead of Platform.

* Document the bindings, and introduce tests that initialize multiple WidgetsBindings with different environments.

* Add tests for the flutter platform test.

* Add license headers

* Fix lints

* Remove trailing whitespace

* Respond to Jonahs comments

* Respond to Ians comments

* Mock out the HttpServer in flutter_platform_test

* Mock out the HttpServer in flutter_platform_test

* Explain why we mock out the HttpServer in flutter_platform_test
This commit is contained in:
David Shuckerow
2019-06-28 10:37:27 -07:00
committed by GitHub
parent 66273157f0
commit df6e4d4872
8 changed files with 204 additions and 14 deletions

View File

@@ -19,6 +19,7 @@ import 'package:test_core/src/runner/environment.dart'; // ignore: implementatio
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/platform.dart';
import '../base/process_manager.dart';
import '../compile.dart';
import '../convert.dart';
@@ -384,6 +385,13 @@ class FlutterPlatform extends PlatformPlugin {
throw 'Failed to compile $expression';
}
/// Binds an [HttpServer] serving from `host` on `port`.
///
/// Only intended to be overridden in tests for [FlutterPlatform].
@protected
@visibleForTesting
Future<HttpServer> bind(InternetAddress host, int port) => HttpServer.bind(host, port);
Future<_AsyncError> _startTest(
String testPath,
StreamChannel<dynamic> controller,
@@ -403,7 +411,7 @@ class FlutterPlatform extends PlatformPlugin {
}));
// Prepare our WebSocket server to talk to the engine subproces.
final HttpServer server = await HttpServer.bind(host, port);
final HttpServer server = await bind(host, port);
finalizers.add(() async {
printTrace('test $ourTestCount: shutting down test harness socket server');
await server.close(force: true);
@@ -846,14 +854,22 @@ class FlutterPlatform extends PlatformPlugin {
testPath,
]);
printTrace(command.join(' '));
// If the FLUTTER_TEST environment variable has been set, then pass it on
// for package:flutter_test to handle the value.
//
// If FLUTTER_TEST has not been set, assume from this context that this
// call was invoked by the command 'flutter test'.
final String flutterTest = platform.environment.containsKey('FLUTTER_TEST')
? platform.environment['FLUTTER_TEST']
: 'true';
final Map<String, String> environment = <String, String>{
'FLUTTER_TEST': 'true',
'FLUTTER_TEST': flutterTest,
'FONTCONFIG_FILE': _fontConfigFile.path,
'SERVER_PORT': serverPort.toString(),
};
if (buildTestAssets) {
environment['UNIT_TEST_ASSETS'] = fs.path.join(
flutterProject.directory.path, 'build', 'unit_test_assets');
flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets');
}
return processManager.start(command, environment: environment);
}