Close platform when tests are complete (dispose compiler and delete font files) (#34685)
This commit is contained in:
@@ -68,12 +68,14 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType,
|
||||
InternetAddressType.IPv6: InternetAddress.loopbackIPv6,
|
||||
};
|
||||
|
||||
typedef PlatformPluginRegistration = void Function(FlutterPlatform platform);
|
||||
|
||||
/// Configure the `test` package to work with Flutter.
|
||||
///
|
||||
/// On systems where each [FlutterPlatform] is only used to run one test suite
|
||||
/// (that is, one Dart file with a `*_test.dart` file name and a single `void
|
||||
/// main()`), you can set an observatory port explicitly.
|
||||
void installHook({
|
||||
FlutterPlatform installHook({
|
||||
@required String shellPath,
|
||||
TestWatcher watcher,
|
||||
bool enableObservatory = false,
|
||||
@@ -91,32 +93,40 @@ void installHook({
|
||||
Uri projectRootDirectory,
|
||||
FlutterProject flutterProject,
|
||||
String icudtlPath,
|
||||
PlatformPluginRegistration platformPluginRegistration
|
||||
}) {
|
||||
assert(enableObservatory || (!startPaused && observatoryPort == null));
|
||||
hack.registerPlatformPlugin(
|
||||
<Runtime>[Runtime.vm],
|
||||
() {
|
||||
return FlutterPlatform(
|
||||
shellPath: shellPath,
|
||||
watcher: watcher,
|
||||
machine: machine,
|
||||
enableObservatory: enableObservatory,
|
||||
startPaused: startPaused,
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
explicitObservatoryPort: observatoryPort,
|
||||
host: _kHosts[serverType],
|
||||
port: port,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
projectRootDirectory: projectRootDirectory,
|
||||
flutterProject: flutterProject,
|
||||
icudtlPath: icudtlPath,
|
||||
);
|
||||
}
|
||||
|
||||
// registerPlatformPlugin can be injected for testing since it's not very mock-friendly.
|
||||
platformPluginRegistration ??= (FlutterPlatform platform) {
|
||||
hack.registerPlatformPlugin(
|
||||
<Runtime>[Runtime.vm],
|
||||
() {
|
||||
return platform;
|
||||
}
|
||||
);
|
||||
};
|
||||
final FlutterPlatform platform = FlutterPlatform(
|
||||
shellPath: shellPath,
|
||||
watcher: watcher,
|
||||
machine: machine,
|
||||
enableObservatory: enableObservatory,
|
||||
startPaused: startPaused,
|
||||
disableServiceAuthCodes: disableServiceAuthCodes,
|
||||
explicitObservatoryPort: observatoryPort,
|
||||
host: _kHosts[serverType],
|
||||
port: port,
|
||||
precompiledDillPath: precompiledDillPath,
|
||||
precompiledDillFiles: precompiledDillFiles,
|
||||
trackWidgetCreation: trackWidgetCreation,
|
||||
updateGoldens: updateGoldens,
|
||||
buildTestAssets: buildTestAssets,
|
||||
projectRootDirectory: projectRootDirectory,
|
||||
flutterProject: flutterProject,
|
||||
icudtlPath: icudtlPath,
|
||||
);
|
||||
platformPluginRegistration(platform);
|
||||
return platform;
|
||||
}
|
||||
|
||||
/// Generates the bootstrap entry point script that will be used to launch an
|
||||
|
||||
@@ -105,7 +105,7 @@ Future<int> runTests(
|
||||
final InternetAddressType serverType =
|
||||
ipv6 ? InternetAddressType.IPv6 : InternetAddressType.IPv4;
|
||||
|
||||
loader.installHook(
|
||||
final loader.FlutterPlatform platform = loader.installHook(
|
||||
shellPath: shellPath,
|
||||
watcher: watcher,
|
||||
enableObservatory: enableObservatory,
|
||||
@@ -145,5 +145,6 @@ Future<int> runTests(
|
||||
return exitCode;
|
||||
} finally {
|
||||
fs.currentDirectory = saved;
|
||||
await platform.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/test/flutter_platform.dart';
|
||||
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -24,6 +25,58 @@ void main() {
|
||||
flutterPlatfrom.loadChannel('test1.dart', MockPlatform());
|
||||
expect(() => flutterPlatfrom.loadChannel('test2.dart', MockPlatform()), throwsA(isA<ToolExit>()));
|
||||
});
|
||||
|
||||
testUsingContext('installHook creates a FlutterPlatform', () {
|
||||
expect(() => installHook(
|
||||
shellPath: 'abc',
|
||||
enableObservatory: false,
|
||||
startPaused: true
|
||||
), throwsA(isA<AssertionError>()));
|
||||
|
||||
expect(() => installHook(
|
||||
shellPath: 'abc',
|
||||
enableObservatory: false,
|
||||
startPaused: false,
|
||||
observatoryPort: 123
|
||||
), throwsA(isA<AssertionError>()));
|
||||
|
||||
FlutterPlatform capturedPlatform;
|
||||
final Map<String, String> expectedPrecompiledDillFiles = <String, String>{'Key': 'Value'};
|
||||
final FlutterPlatform flutterPlatform = installHook(
|
||||
shellPath: 'abc',
|
||||
enableObservatory: true,
|
||||
machine: true,
|
||||
startPaused: true,
|
||||
disableServiceAuthCodes: true,
|
||||
port: 100,
|
||||
precompiledDillPath: 'def',
|
||||
precompiledDillFiles: expectedPrecompiledDillFiles,
|
||||
trackWidgetCreation: true,
|
||||
updateGoldens: true,
|
||||
buildTestAssets: true,
|
||||
observatoryPort: 200,
|
||||
serverType: InternetAddressType.IPv6,
|
||||
icudtlPath: 'ghi',
|
||||
platformPluginRegistration: (FlutterPlatform platform) {
|
||||
capturedPlatform = platform;
|
||||
});
|
||||
|
||||
expect(identical(capturedPlatform, flutterPlatform), equals(true));
|
||||
expect(flutterPlatform.shellPath, equals('abc'));
|
||||
expect(flutterPlatform.enableObservatory, equals(true));
|
||||
expect(flutterPlatform.machine, equals(true));
|
||||
expect(flutterPlatform.startPaused, equals(true));
|
||||
expect(flutterPlatform.disableServiceAuthCodes, equals(true));
|
||||
expect(flutterPlatform.port, equals(100));
|
||||
expect(flutterPlatform.host, InternetAddress.loopbackIPv6);
|
||||
expect(flutterPlatform.explicitObservatoryPort, equals(200));
|
||||
expect(flutterPlatform.precompiledDillPath, equals('def'));
|
||||
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
|
||||
expect(flutterPlatform.trackWidgetCreation, equals(true));
|
||||
expect(flutterPlatform.updateGoldens, equals(true));
|
||||
expect(flutterPlatform.buildTestAssets, equals(true));
|
||||
expect(flutterPlatform.icudtlPath, equals('ghi'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user