@@ -10,26 +10,20 @@ import 'package:shelf/shelf.dart';
1010import 'package:shelf/shelf_io.dart' as shelf_io;
1111import 'package:shelf_static/shelf_static.dart' ;
1212
13- /// Runs Chrome, opens the given `appUrl` , and returns the result reported by the
14- /// app.
13+ /// Runs Chrome and returns the result reported by the app.
1514///
1615/// The app is served from the `appDirectory` . Typically, the app is built
1716/// using `flutter build web` and served from `build/web` .
1817///
1918/// The launched app is expected to report the result by sending an HTTP POST
2019/// request to "/test-result" containing result data as plain text body of the
2120/// request. This function has no opinion about what that string contains.
22- Future <String > evalTestAppInChrome ({
23- required String appUrl,
24- required String appDirectory,
25- int serverPort = 8080 ,
26- int browserDebugPort = 8081 ,
27- }) async {
21+ Future <String > evalTestAppInChrome ({required String appDirectory}) async {
2822 io.HttpServer ? server;
2923 Chrome ? chrome;
3024 try {
3125 final resultCompleter = Completer <String >();
32- server = await io.HttpServer .bind ('localhost' , serverPort );
26+ server = await io.HttpServer .bind ('localhost' , 0 );
3327 final Cascade cascade = Cascade ()
3428 .add ((Request request) async {
3529 if (request.requestedUri.path.endsWith ('/test-result' )) {
@@ -46,8 +40,8 @@ Future<String> evalTestAppInChrome({
4640 chrome = await Chrome .launch (
4741 ChromeOptions (
4842 headless: true ,
49- debugPort: browserDebugPort ,
50- url: appUrl ,
43+ debugPort: 0 ,
44+ url: 'http://localhost:${ server . port }/index.html' ,
5145 userDataDirectory: userDataDirectory.path,
5246 windowHeight: 500 ,
5347 windowWidth: 500 ,
@@ -67,17 +61,14 @@ class AppServer {
6761 AppServer ._(this ._server, this .chrome, this .onChromeError);
6862
6963 static Future <AppServer > start ({
70- required String appUrl,
7164 required String appDirectory,
7265 required String cacheControl,
73- int serverPort = 8080 ,
74- int browserDebugPort = 8081 ,
7566 bool headless = true ,
7667 List <Handler >? additionalRequestHandlers,
7768 }) async {
7869 io.HttpServer server;
7970 Chrome chrome;
80- server = await io.HttpServer .bind ('localhost' , serverPort );
71+ server = await io.HttpServer .bind ('localhost' , 0 );
8172 final Handler staticHandler = createStaticHandler (appDirectory, defaultDocument: 'index.html' );
8273 var cascade = Cascade ();
8374 if (additionalRequestHandlers != null ) {
@@ -97,8 +88,8 @@ class AppServer {
9788 chrome = await Chrome .launch (
9889 ChromeOptions (
9990 headless: headless,
100- debugPort: browserDebugPort ,
101- url: appUrl ,
91+ debugPort: 0 ,
92+ url: 'http://localhost:${ server . port }/index.html' ,
10293 userDataDirectory: userDataDirectory.path,
10394 ),
10495 onError: chromeErrorCompleter.complete,
0 commit comments