Launch DevTools from pub instead of devtools_server (#71737)

* Launch DevTools from pub instead of devtools_server
This commit is contained in:
Kenzie Schmoll
2020-12-14 10:12:42 -08:00
committed by GitHub
parent f35238c804
commit cd452286ab
10 changed files with 284 additions and 76 deletions

View File

@@ -0,0 +1,119 @@
// 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 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/devtools_launcher.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
testWithoutContext('DevtoolsLauncher launches DevTools through pub and saves the URI', () async {
final Completer<void> completer = Completer<void>();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'pub',
'global',
'activate',
'devtools',
],
stdout: 'Activated DevTools 0.9.5',
),
FakeCommand(
command: const <String>[
'pub',
'global',
'run',
'devtools',
],
stdout: 'Serving DevTools at http://127.0.0.1:9100\n',
completer: completer,
),
]),
);
final DevToolsServerAddress address = await launcher.serve();
expect(address.host, '127.0.0.1');
expect(address.port, 9100);
});
testWithoutContext('DevtoolsLauncher prints error if exception is thrown during activate', () async {
final BufferLogger logger = BufferLogger.test();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'pub',
'global',
'activate',
'devtools',
],
stderr: 'Error - could not activate devtools',
exitCode: 1,
),
FakeCommand(
command: const <String>[
'pub',
'global',
'run',
'devtools',
'--vm-uri=http://127.0.0.1:1234/abcdefg',
],
onRun: () {
throw const ProcessException('pub', <String>[]);
}
)
]),
);
await launcher.launch(Uri.parse('http://127.0.0.1:1234/abcdefg'));
expect(logger.errorText, contains('Error running `pub global activate devtools`:\nError - could not activate devtools'));
});
testWithoutContext('DevtoolsLauncher prints error if exception is thrown during launch', () async {
final BufferLogger logger = BufferLogger.test();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'pub',
'global',
'activate',
'devtools',
],
stdout: 'Activated DevTools 0.9.5',
),
FakeCommand(
command: const <String>[
'pub',
'global',
'run',
'devtools',
'--vm-uri=http://127.0.0.1:1234/abcdefg',
],
onRun: () {
throw const ProcessException('pub', <String>[]);
}
)
]),
);
await launcher.launch(Uri.parse('http://127.0.0.1:1234/abcdefg'));
expect(logger.errorText, contains('Failed to launch DevTools: ProcessException'));
});
}

View File

@@ -289,7 +289,7 @@ void main() {
when(mockResidentRunner.supportsServiceProtocol).thenReturn(true);
await terminalHandler.processTerminalInput('v');
verify(mockResidentRunner.launchDevTools()).called(1);
verify(mockResidentRunner.launchDevTools(openInBrowser: true)).called(1);
});
testWithoutContext('w,W - debugDumpApp with service protocol', () async {

View File

@@ -118,16 +118,12 @@ class _FakeProcess implements Process {
_FakeProcess(
this._exitCode,
Duration duration,
VoidCallback onRun,
this.pid,
this._stderr,
this.stdin,
this._stdout,
this._completer,
) : exitCode = Future<void>.delayed(duration).then((void value) {
if (onRun != null) {
onRun();
}
if (_completer != null) {
return _completer.future.then((void _) => _exitCode);
}
@@ -231,10 +227,12 @@ abstract class FakeProcessManager implements ProcessManager {
) {
_pid += 1;
final FakeCommand fakeCommand = findCommand(command, workingDirectory, environment, encoding);
if (fakeCommand.onRun != null) {
fakeCommand.onRun();
}
return _FakeProcess(
fakeCommand.exitCode,
fakeCommand.duration,
fakeCommand.onRun,
_pid,
fakeCommand.stderr,
fakeCommand.stdin,