Unverified Commit 52415cb0 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

baby-steps to testing/refactoring flutter_platform (#31616)

parent eca93640
...@@ -74,7 +74,7 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType, ...@@ -74,7 +74,7 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType,
/// Configure the `test` package to work with Flutter. /// Configure the `test` package to work with Flutter.
/// ///
/// On systems where each [_FlutterPlatform] is only used to run one test suite /// 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 /// (that is, one Dart file with a `*_test.dart` file name and a single `void
/// main()`), you can set an observatory port explicitly. /// main()`), you can set an observatory port explicitly.
void installHook({ void installHook({
...@@ -99,25 +99,27 @@ void installHook({ ...@@ -99,25 +99,27 @@ void installHook({
assert(enableObservatory || (!startPaused && observatoryPort == null)); assert(enableObservatory || (!startPaused && observatoryPort == null));
hack.registerPlatformPlugin( hack.registerPlatformPlugin(
<Runtime>[Runtime.vm], <Runtime>[Runtime.vm],
() => _FlutterPlatform( () {
shellPath: shellPath, return FlutterPlatform(
watcher: watcher, shellPath: shellPath,
machine: machine, watcher: watcher,
enableObservatory: enableObservatory, machine: machine,
startPaused: startPaused, enableObservatory: enableObservatory,
disableServiceAuthCodes: disableServiceAuthCodes, startPaused: startPaused,
explicitObservatoryPort: observatoryPort, disableServiceAuthCodes: disableServiceAuthCodes,
host: _kHosts[serverType], explicitObservatoryPort: observatoryPort,
port: port, host: _kHosts[serverType],
precompiledDillPath: precompiledDillPath, port: port,
precompiledDillFiles: precompiledDillFiles, precompiledDillPath: precompiledDillPath,
trackWidgetCreation: trackWidgetCreation, precompiledDillFiles: precompiledDillFiles,
updateGoldens: updateGoldens, trackWidgetCreation: trackWidgetCreation,
buildTestAssets: buildTestAssets, updateGoldens: updateGoldens,
projectRootDirectory: projectRootDirectory, buildTestAssets: buildTestAssets,
flutterProject: flutterProject, projectRootDirectory: projectRootDirectory,
icudtlPath: icudtlPath, flutterProject: flutterProject,
), icudtlPath: icudtlPath,
);
}
); );
} }
...@@ -380,8 +382,9 @@ class _Compiler { ...@@ -380,8 +382,9 @@ class _Compiler {
} }
} }
class _FlutterPlatform extends PlatformPlugin { /// The flutter test platform used to integrate with package:test.
_FlutterPlatform({ class FlutterPlatform extends PlatformPlugin {
FlutterPlatform({
@required this.shellPath, @required this.shellPath,
this.watcher, this.watcher,
this.enableObservatory, this.enableObservatory,
...@@ -462,14 +465,16 @@ class _FlutterPlatform extends PlatformPlugin { ...@@ -462,14 +465,16 @@ class _FlutterPlatform extends PlatformPlugin {
} }
@override @override
StreamChannel<dynamic> loadChannel(String testPath, SuitePlatform platform) { StreamChannel<dynamic> loadChannel(String path, SuitePlatform platform) {
if (_testCount > 0) { if (_testCount > 0) {
// Fail if there will be a port conflict. // Fail if there will be a port conflict.
if (explicitObservatoryPort != null) if (explicitObservatoryPort != null) {
throwToolExit('installHook() was called with an observatory port or debugger mode enabled, but then more than one test suite was run.'); throwToolExit('installHook() was called with an observatory port or debugger mode enabled, but then more than one test suite was run.');
}
// Fail if we're passing in a precompiled entry-point. // Fail if we're passing in a precompiled entry-point.
if (precompiledDillPath != null) if (precompiledDillPath != null) {
throwToolExit('installHook() was called with a precompiled test entry-point, but then more than one test suite was run.'); throwToolExit('installHook() was called with a precompiled test entry-point, but then more than one test suite was run.');
}
} }
final int ourTestCount = _testCount; final int ourTestCount = _testCount;
_testCount += 1; _testCount += 1;
...@@ -488,7 +493,7 @@ class _FlutterPlatform extends PlatformPlugin { ...@@ -488,7 +493,7 @@ class _FlutterPlatform extends PlatformPlugin {
localController.stream, localController.stream,
remoteSink, remoteSink,
); );
testCompleteCompleter.complete(_startTest(testPath, localChannel, ourTestCount)); testCompleteCompleter.complete(_startTest(path, localChannel, ourTestCount));
return remoteChannel; return remoteChannel;
} }
......
// Copyright 2019 The Chromium 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 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/test/flutter_platform.dart';
import 'package:mockito/mockito.dart';
import 'package:test_core/backend.dart';
import 'src/common.dart';
import 'src/context.dart';
void main() {
group('FlutterPlatform', () {
testUsingContext('ensureConfiguration throws an error if an explicitObservatoryPort is specified and more than one test file', () async {
final FlutterPlatform flutterPlatfrom = FlutterPlatform(shellPath: '/', explicitObservatoryPort: 1234);
flutterPlatfrom.loadChannel('test1.dart', MockPlatform());
expect(() => flutterPlatfrom.loadChannel('test2.dart', MockPlatform()), throwsA(isA<ToolExit>()));
});
testUsingContext('ensureConfiguration throws an error if a precompiled entrypoint is specified and more that one test file', () {
final FlutterPlatform flutterPlatfrom = FlutterPlatform(shellPath: '/', precompiledDillPath: 'example.dill');
flutterPlatfrom.loadChannel('test1.dart', MockPlatform());
expect(() => flutterPlatfrom.loadChannel('test2.dart', MockPlatform()), throwsA(isA<ToolExit>()));
});
});
}
class MockPlatform extends Mock implements SuitePlatform {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment