Unverified Commit 24f8f799 authored by Dan Field's avatar Dan Field Committed by GitHub

add an --enable-vmservice flag (#50663)

parent 58a4122b
......@@ -142,7 +142,8 @@ Future<void> run(List<String> args) async {
tests[source] = dill;
}
exitCode = await runTests(
// TODO(dnfield): This should be injected.
exitCode = await const FlutterTestRunner().runTests(
const TestWrapper(),
tests.keys.toList(),
workDir: testDirectory,
......
......@@ -27,6 +27,7 @@ class TestCommand extends FastFlutterCommand {
TestCommand({
bool verboseHelp = false,
this.testWrapper = const TestWrapper(),
this.testRunner = const FlutterTestRunner(),
}) : assert(testWrapper != null) {
requiresPubspecYaml();
usesPubOption();
......@@ -110,6 +111,15 @@ class TestCommand extends FastFlutterCommand {
'test cases (must be a 32bit unsigned integer).\n'
'If "random", pick a random seed to use.\n'
'If 0 or not set, do not randomize test case execution order.',
)
..addFlag('enable-vmservice',
defaultsTo: false,
hide: !verboseHelp,
help: 'Enables the vmservice without --start-paused. This flag is '
'intended for use with tests that will use dart:developer to '
'interact with the vmservice at runtime.\n'
'This flag is ignored if --start-paused or coverage are requested. '
'The vmservice will be enabled no matter what in those cases.'
);
usesTrackWidgetCreation(verboseHelp: verboseHelp);
}
......@@ -117,6 +127,9 @@ class TestCommand extends FastFlutterCommand {
/// The interface for starting and configuring the tester.
final TestWrapper testWrapper;
/// Interface for running the tester process.
final FlutterTestRunner testRunner;
@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
final Set<DevelopmentArtifact> results = <DevelopmentArtifact>{};
......@@ -235,14 +248,14 @@ class TestCommand extends FastFlutterCommand {
final bool disableServiceAuthCodes =
boolArg('disable-service-auth-codes');
final int result = await runTests(
final int result = await testRunner.runTests(
testWrapper,
files,
workDir: workDir,
names: names,
plainNames: plainNames,
watcher: watcher,
enableObservatory: collector != null || startPaused,
enableObservatory: collector != null || startPaused || boolArg('enable-vmservice'),
startPaused: startPaused,
disableServiceAuthCodes: disableServiceAuthCodes,
ipv6: boolArg('ipv6'),
......
......@@ -7,9 +7,13 @@ import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/test.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/test/runner.dart';
import 'package:flutter_tools/src/test/test_wrapper.dart';
import 'package:flutter_tools/src/test/watcher.dart';
import 'package:process/process.dart';
import '../../src/common.dart';
......@@ -73,6 +77,92 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
Cache: () => FakeCache(),
});
testUsingContext('Pipes enable-observatory', () async {
final FakeFlutterTestRunner testRunner = FakeFlutterTestRunner(0);
final TestCommand testCommand = TestCommand(testRunner: testRunner);
final CommandRunner<void> commandRunner =
createTestCommandRunner(testCommand);
await commandRunner.run(const <String>[
'test',
'--no-pub',
'--enable-vmservice',
'--',
'test/fake_test.dart',
]);
expect(
testRunner.lastEnableObservatoryValue,
true,
);
await commandRunner.run(const <String>[
'test',
'--no-pub',
'--start-paused',
'--no-enable-vmservice',
'--',
'test/fake_test.dart',
]);
expect(
testRunner.lastEnableObservatoryValue,
true,
);
await commandRunner.run(const <String>[
'test',
'--no-pub',
'--',
'test/fake_test.dart',
]);
expect(
testRunner.lastEnableObservatoryValue,
false,
);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Cache: () => FakeCache(),
});
}
class FakeFlutterTestRunner implements FlutterTestRunner {
FakeFlutterTestRunner(this.exitCode);
int exitCode;
bool lastEnableObservatoryValue;
@override
Future<int> runTests(
TestWrapper testWrapper,
List<String> testFiles, {
Directory workDir,
List<String> names = const <String>[],
List<String> plainNames = const <String>[],
bool enableObservatory = false,
bool startPaused = false,
bool disableServiceAuthCodes = false,
bool ipv6 = false,
bool machine = false,
String precompiledDillPath,
Map<String, String> precompiledDillFiles,
BuildMode buildMode,
bool trackWidgetCreation = false,
bool updateGoldens = false,
TestWatcher watcher,
int concurrency,
bool buildTestAssets = false,
FlutterProject flutterProject,
String icudtlPath,
Directory coverageDirectory,
bool web = false,
String randomSeed = '0',
}) async {
lastEnableObservatoryValue = enableObservatory;
return exitCode;
}
}
class FakePackageTest implements TestWrapper {
......
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