Revert "[flutter_tools] Serve DevTools at app start (#73366)" (#73896)

This reverts commit 1cb0a24a46.
This commit is contained in:
Jenn Magder
2021-01-13 13:57:09 -08:00
committed by GitHub
parent c9b991d115
commit 388dcd2478
17 changed files with 116 additions and 557 deletions

View File

@@ -4,41 +4,20 @@
import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/devtools_launcher.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/persistent_tool_state.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
BufferLogger logger;
FakePlatform platform;
PersistentToolState persistentToolState;
setUp(() {
logger = BufferLogger.test();
platform = FakePlatform(environment: <String, String>{});
final Directory tempDir = globals.fs.systemTempDirectory.createTempSync('devtools_launcher_test');
persistentToolState = PersistentToolState.test(
directory: tempDir,
logger: logger,
);
});
testWithoutContext('DevtoolsLauncher launches DevTools through pub and saves the URI', () async {
final Completer<void> completer = Completer<void>();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
platform: platform,
persistentToolState: persistentToolState,
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
@@ -49,14 +28,6 @@ void main() {
],
stdout: 'Activated DevTools 0.9.5',
),
const FakeCommand(
command: <String>[
'pub',
'global',
'list',
],
stdout: 'devtools 0.9.6',
),
FakeCommand(
command: const <String>[
'pub',
@@ -80,9 +51,7 @@ void main() {
final Completer<void> completer = Completer<void>();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
platform: platform,
persistentToolState: persistentToolState,
logger: BufferLogger.test(),
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
@@ -93,21 +62,12 @@ void main() {
],
stdout: 'Activated DevTools 0.9.5',
),
const FakeCommand(
command: <String>[
'pub',
'global',
'list',
],
stdout: 'devtools 0.9.6',
),
FakeCommand(
command: const <String>[
'pub',
'global',
'run',
'devtools',
'--no-launch-browser',
],
stdout: 'Serving DevTools at http://127.0.0.1:9100\n',
completer: completer,
@@ -115,49 +75,16 @@ void main() {
]),
);
final DevToolsServerAddress address = await launcher.serve();
final DevToolsServerAddress address = await launcher.serve(openInBrowser: true);
expect(address.host, '127.0.0.1');
expect(address.port, 9100);
});
testWithoutContext('DevtoolsLauncher does not activate DevTools if it was recently activated', () async {
persistentToolState.lastDevToolsActivationTime = DateTime.now();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
platform: platform,
persistentToolState: persistentToolState,
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
'pub',
'global',
'list',
],
stdout: 'devtools 0.9.6',
),
const FakeCommand(
command: <String>[
'pub',
'global',
'run',
'devtools',
'--no-launch-browser',
],
stdout: 'Serving DevTools at http://127.0.0.1:9100\n',
),
]),
);
await launcher.serve();
});
testWithoutContext('DevtoolsLauncher prints error if exception is thrown during activate', () async {
final BufferLogger logger = BufferLogger.test();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
platform: platform,
persistentToolState: persistentToolState,
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
@@ -169,14 +96,6 @@ void main() {
stderr: 'Error - could not activate devtools',
exitCode: 1,
),
const FakeCommand(
command: <String>[
'pub',
'global',
'list',
],
stdout: 'devtools 0.9.6',
),
FakeCommand(
command: const <String>[
'pub',
@@ -199,11 +118,10 @@ void main() {
});
testWithoutContext('DevtoolsLauncher prints error if exception is thrown during launch', () async {
final BufferLogger logger = BufferLogger.test();
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
pubExecutable: 'pub',
logger: logger,
platform: platform,
persistentToolState: persistentToolState,
processManager: FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>[
@@ -214,14 +132,6 @@ void main() {
],
stdout: 'Activated DevTools 0.9.5',
),
const FakeCommand(
command: <String>[
'pub',
'global',
'list',
],
stdout: 'devtools 0.9.6',
),
FakeCommand(
command: const <String>[
'pub',

View File

@@ -57,23 +57,4 @@ void main() {
expect(state2.lastActiveVersion(Channel.beta), 'ghi');
expect(state2.lastActiveVersion(Channel.stable), 'jkl');
});
testWithoutContext('lastDevToolsActivationTime can be cached and stored', () {
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final Directory directory = fileSystem.directory('state_dir')..createSync();
final PersistentToolState state1 = PersistentToolState.test(
directory: directory,
logger: BufferLogger.test(),
);
final DateTime time = DateTime.now();
state1.lastDevToolsActivationTime = time;
final PersistentToolState state2 = PersistentToolState.test(
directory: directory,
logger: BufferLogger.test(),
);
expect(state2.lastDevToolsActivationTime, equals(time));
});
}

View File

@@ -229,9 +229,7 @@ void main() {
expect((await connectionInfo).baseUri, 'foo://bar');
expect(onAppStart.isCompleted, true);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner suppresses errors for the initial compilation', () => testbed.run(() async {
globals.fs.file(globals.fs.path.join('lib', 'main.dart'))
@@ -276,9 +274,7 @@ void main() {
suppressErrors: true,
)).called(1);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
// Regression test for https://github.com/flutter/flutter/issues/60613
testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails', () => testbed.run(() async {
@@ -410,9 +406,7 @@ void main() {
suppressErrors: false,
)).called(1);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can attach to device successfully with --fast-start', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -492,9 +486,7 @@ void main() {
expect((await connectionInfo).baseUri, 'foo://bar');
expect(onAppStart.isCompleted, true);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can handle an RPC exception from hot reload', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -547,9 +539,7 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
Usage: () => MockUsage(),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner fails its operation if the device initialization is not complete', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -634,9 +624,7 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
Usage: () => MockUsage(),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner reports hot reload event with null safety analytics', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -700,7 +688,6 @@ void main() {
})).called(1);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
Usage: () => MockUsage(),
}));
@@ -769,9 +756,7 @@ void main() {
expect(result.code, 0);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner reports error with missing entrypoint file', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -855,9 +840,7 @@ void main() {
expect(testLogger.errorText, contains('The entrypoint file (i.e. the file with main())'));
expect(result.fatal, false);
expect(result.code, 0);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner resets compilation time on reload reject', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -945,9 +928,7 @@ void main() {
expect(result.message, contains('Reload rejected: Failed to hot reload')); // contains error message from reload report.
expect(result.code, 1);
verify(mockDevFS.resetLastCompiled()).called(1); // compilation time is reset.
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can send target platform to analytics from hot reload', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1019,9 +1000,7 @@ void main() {
);
}, overrides: <Type, Generator>{
Usage: () => MockUsage(),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can perform fast reassemble', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1135,9 +1114,7 @@ void main() {
ProjectFileInvalidator: () => FakeProjectFileInvalidator(),
Usage: () => MockUsage(),
FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can send target platform to analytics from full restart', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1207,9 +1184,7 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
Usage: () => MockUsage(),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner can remove breakpoints from paused isolate during hot restart', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1285,9 +1260,7 @@ void main() {
expect(result.isOk, true);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner will alternative the name of the dill file uploaded for a hot restart', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1419,9 +1392,7 @@ void main() {
await residentRunner.restart(fullRestart: true);
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner Can handle an RPC exception from hot restart', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -1474,9 +1445,7 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
Usage: () => MockUsage(),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ResidentRunner uses temp directory when there is no output dill path', () => testbed.run(() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
@@ -1681,88 +1650,13 @@ void main() {
)
}));
testUsingContext('ResidentRunner invokes DevToolsLauncher when attaching and shutting down DevTools', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
listViews,
setAssetBundlePath,
]);
final Future<int> result = residentRunner.attach();
expect(await result, 0);
testUsingContext('ResidentRunner invokes DevtoolsLauncher when launching and shutting down Devtools', () => testbed.run(() async {
when(mockFlutterDevice.vmService).thenReturn(fakeVmServiceHost.vmService);
setHttpAddress(testUri, fakeVmServiceHost.vmService);
await residentRunner.launchDevTools();
verify(mockDevtoolsLauncher.launch(testUri)).called(1);
// Verify DevTools was served.
verify(mockDevtoolsLauncher.serve()).called(1);
// Shutdown
await residentRunner.shutdownDevTools();
verify(mockDevtoolsLauncher.close()).called(1);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
testUsingContext('ResidentRunner invokes DevtoolsLauncher when attaching and shutting down - cold mode', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
listViews,
setAssetBundlePath,
]);
residentRunner = ColdRunner(
<FlutterDevice>[
mockFlutterDevice,
],
stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
target: 'main.dart',
);
when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route'),
)).thenAnswer((Invocation invocation) async {
return 0;
});
final Future<int> result = residentRunner.attach();
expect(await result, 0);
// Verify DevTools was served.
verify(mockDevtoolsLauncher.serve()).called(1);
// Shutdown
await residentRunner.shutdownDevTools();
verify(mockDevtoolsLauncher.close()).called(1);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
testUsingContext('ResidentRunner invokes DevtoolsLauncher when running and shutting down - cold mode', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
listViews,
setAssetBundlePath,
]);
residentRunner = ColdRunner(
<FlutterDevice>[
mockFlutterDevice,
],
stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'),
target: 'main.dart',
);
when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route'),
)).thenAnswer((Invocation invocation) async {
return 0;
});
final Future<int> result = residentRunner.run();
expect(await result, 0);
// Verify DevTools was served.
verify(mockDevtoolsLauncher.serve()).called(1);
// Shutdown
await residentRunner.shutdownDevTools();
await residentRunner.shutdownDevtools();
verify(mockDevtoolsLauncher.close()).called(1);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
@@ -2405,9 +2299,7 @@ void main() {
await residentRunner.run();
expect(await globals.fs.file('foo').readAsString(), testUri.toString());
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner copies compiled app.dill to cache during startup', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2435,9 +2327,7 @@ void main() {
await residentRunner.run();
expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill')).readAsString(), 'ABC');
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner copies compiled app.dill to cache during startup with dart defines', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2473,9 +2363,7 @@ void main() {
expect(await globals.fs.file(globals.fs.path.join(
'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC');
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2511,9 +2399,7 @@ void main() {
expect(await globals.fs.file(globals.fs.path.join(
'build', '3416d3007730479552122f01c01e326d.cache.dill')).readAsString(), 'ABC');
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2542,9 +2428,7 @@ void main() {
await residentRunner.run();
expect(globals.fs.file(globals.fs.path.join('build', 'cache.dill')), isNot(exists));
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner copies compiled app.dill to cache during startup with --track-widget-creation', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2577,9 +2461,7 @@ void main() {
await residentRunner.run();
expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC');
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner unforwards device ports', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2612,9 +2494,7 @@ void main() {
await residentRunner.run();
verify(mockPortForwarder.dispose()).called(1);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('HotRunner handles failure to write vmservice file', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
@@ -2643,9 +2523,7 @@ void main() {
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
FileSystem: () => ThrowingForwardingFileSystem(MemoryFileSystem.test()),
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('ColdRunner writes vm service file when providing debugging option', () => testbed.run(() async {
@@ -2672,9 +2550,7 @@ void main() {
expect(await globals.fs.file('foo').readAsString(), testUri.toString());
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}), overrides: <Type, Generator>{
DevtoolsLauncher: () => mockDevtoolsLauncher,
});
}));
testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);

View File

@@ -290,48 +290,6 @@ void main() {
expect(FlutterCommandResult.warning().exitStatus, ExitStatus.warning);
});
testUsingContext('devToolsServerAddress returns parsed uri', () async {
final DummyFlutterCommand command = DummyFlutterCommand()..addDevToolsOptions();
await createTestCommandRunner(command).run(<String>[
'dummy',
'--${FlutterCommand.kDevToolsServerAddress}',
'http://127.0.0.1:9105',
]);
expect(command.devToolsServerAddress.toString(), equals('http://127.0.0.1:9105'));
});
testUsingContext('devToolsServerAddress returns null for bad input', () async {
final DummyFlutterCommand command = DummyFlutterCommand()..addDevToolsOptions();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>[
'dummy',
'--${FlutterCommand.kDevToolsServerAddress}',
'hello-world',
]);
expect(command.devToolsServerAddress, isNull);
await runner.run(<String>[
'dummy',
'--${FlutterCommand.kDevToolsServerAddress}',
'',
]);
expect(command.devToolsServerAddress, isNull);
await runner.run(<String>[
'dummy',
'--${FlutterCommand.kDevToolsServerAddress}',
'9101',
]);
expect(command.devToolsServerAddress, isNull);
await runner.run(<String>[
'dummy',
'--${FlutterCommand.kDevToolsServerAddress}',
'127.0.0.1:9101',
]);
expect(command.devToolsServerAddress, isNull);
});
group('signals tests', () {
MockIoProcessSignal mockSignal;
ProcessSignal signalUnderTest;

View File

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