@@ -35,50 +35,10 @@ Future<void> runFlutterIntegrationTest(
3535 // TODO(https://github.com/flutter/devtools/issues/9196): support starting
3636 // DTD and passing the URI to DevTools server. Workspace roots should be set
3737 // on the DTD instance based on the connected test app.
38-
39- // Start the DevTools server. This will use the DevTools server that is
40- // shipped with the Dart SDK.
41- // TODO(https://github.com/flutter/devtools/issues/9197): launch the
42- // DevTools server from source so that end to end changes (server + app) can
43- // be tested.
44- devToolsServerProcess = await Process .start ('dart' , [
45- 'devtools' ,
46- // Do not launch DevTools app in the browser. This DevTools server
47- // instance will be used to connect to the DevTools app that is run from
48- // Flutter driver from the integration test runner.
49- '--no-launch-browser' ,
50- // Disable CORS restrictions so that we can connect to the server from
51- // DevTools app that is served on a different origin.
52- '--disable-cors' ,
53- ]);
54-
55- final addressCompleter = Completer <void >();
56- final sub = devToolsServerProcess.stdout.transform (utf8.decoder).listen ((
57- line,
58- ) {
59- if (line.startsWith (_devToolsServerAddressLine)) {
60- // This will pull the server address from a String like:
61- // "Serving DevTools at http://127.0.0.1:9104.".
62- final regexp = RegExp (
63- r'http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+' ,
64- );
65- final match = regexp.firstMatch (line);
66- if (match != null ) {
67- devToolsServerAddress = match.group (0 );
68- addressCompleter.complete ();
69- }
70- }
71- });
72-
73- await addressCompleter.future.timeout (
74- const Duration (seconds: 10 ),
75- onTimeout: () async {
76- await sub.cancel ();
77- devToolsServerProcess? .kill ();
78- throw Exception ('Timed out waiting for DevTools server to start.' );
79- },
38+ devToolsServerProcess = await startDevToolsServer ();
39+ devToolsServerAddress = await listenForDevToolsAddress (
40+ devToolsServerProcess,
8041 );
81- await sub.cancel ();
8242 }
8343
8444 if (! offline) {
@@ -195,3 +155,60 @@ class DevToolsAppTestRunnerArgs extends IntegrationTestRunnerArgs {
195155 );
196156 }
197157}
158+
159+ /// Starts the DevTools server.
160+ ///
161+ /// Note: This will use the DevTools server that is shipped with the Dart SDK.
162+ ///
163+ /// TODO(https://github.com/flutter/devtools/issues/9197): launch the
164+ /// DevTools server from source so that end to end changes (server + app) can
165+ /// be tested.
166+ Future <Process > startDevToolsServer () async {
167+ final devToolsServerProcess = await Process .start ('dart' , [
168+ 'devtools' ,
169+ // Do not launch DevTools app in the browser. This DevTools server
170+ // instance will be used to connect to the DevTools app that is run from
171+ // Flutter driver from the integration test runner.
172+ '--no-launch-browser' ,
173+ // Disable CORS restrictions so that we can connect to the server from
174+ // DevTools app that is served on a different origin.
175+ '--disable-cors' ,
176+ ]);
177+ return devToolsServerProcess;
178+ }
179+
180+ /// Listens on the [devToolsServerProcess] stdout for the DevTool's address and
181+ /// returns it.
182+ Future <String > listenForDevToolsAddress (
183+ Process devToolsServerProcess, {
184+ Duration timeout = const Duration (seconds: 10 ),
185+ }) async {
186+ final devToolsAddressCompleter = Completer <String >();
187+
188+ final sub = devToolsServerProcess.stdout.transform (utf8.decoder).listen ((
189+ line,
190+ ) {
191+ if (line.startsWith (_devToolsServerAddressLine)) {
192+ // This will pull the server address from a String like:
193+ // "Serving DevTools at http://127.0.0.1:9104.".
194+ final regexp = RegExp (r'http:\/\/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+' );
195+ final match = regexp.firstMatch (line);
196+ if (match != null ) {
197+ final devToolsServerAddress = match.group (0 );
198+ devToolsAddressCompleter.complete (devToolsServerAddress);
199+ }
200+ }
201+ });
202+
203+ await devToolsAddressCompleter.future.timeout (
204+ timeout,
205+ onTimeout: () async {
206+ await sub.cancel ();
207+ devToolsServerProcess.kill ();
208+ throw Exception ('Timed out waiting for DevTools server to start.' );
209+ },
210+ );
211+ await sub.cancel ();
212+
213+ return devToolsAddressCompleter.future;
214+ }
0 commit comments