Return the existing DevTools server from DevToolsLauncher.serve if one is already running. (#74271)
* Return the existing DevTools server from DevToolsLauncher.serve if one is already running.
This commit is contained in:
@@ -172,7 +172,9 @@ class DevtoolsServerLauncher extends DevtoolsLauncher {
|
||||
|
||||
@override
|
||||
Future<DevToolsServerAddress> serve() async {
|
||||
await launch(null);
|
||||
if (activeDevToolsServer == null) {
|
||||
await launch(null);
|
||||
}
|
||||
return activeDevToolsServer;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,6 +120,55 @@ void main() {
|
||||
expect(address.port, 9100);
|
||||
});
|
||||
|
||||
testWithoutContext('DevtoolsLauncher does not launch a new DevTools instance if one is already active', () async {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
final DevtoolsLauncher launcher = DevtoolsServerLauncher(
|
||||
pubExecutable: 'pub',
|
||||
logger: logger,
|
||||
platform: platform,
|
||||
persistentToolState: persistentToolState,
|
||||
processManager: FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'pub',
|
||||
'global',
|
||||
'activate',
|
||||
'devtools',
|
||||
],
|
||||
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,
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
DevToolsServerAddress address = await launcher.serve();
|
||||
expect(address.host, '127.0.0.1');
|
||||
expect(address.port, 9100);
|
||||
|
||||
// Call `serve` again and verify that the already running server is returned.
|
||||
address = await launcher.serve();
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user