1+ // Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
15import 'dart:async' ;
2- import 'dart:convert' ;
36import 'dart:io' ;
47
8+ import 'package:build_daemon/client.dart' ;
9+ import 'package:build_daemon/data/build_status.dart' ;
10+ import 'package:build_daemon/data/build_target.dart' ;
11+ import 'package:dwds/dwds.dart' ;
512import 'package:dwds/src/services/chrome_proxy_service.dart' ;
613import 'package:dwds/src/services/debug_service.dart' ;
714import 'package:dwds/src/utilities/shared.dart' ;
@@ -11,21 +18,25 @@ import 'package:test/test.dart';
1118import 'package:webdriver/io.dart' ;
1219import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' ;
1320
21+ import 'server.dart' ;
22+ import 'utilities.dart' ;
23+
1424class TestContext {
1525 String appUrl;
1626 DebugService debugService;
1727 ChromeProxyService get chromeProxyService =>
1828 debugService.chromeProxyService as ChromeProxyService ;
1929 WipConnection tabConnection;
20- Process webdev;
30+ TestServer testServer;
31+ BuildDaemonClient daemonClient;
2132 WebDriver webDriver;
2233 Process chromeDriver;
2334 int port;
2435
25- /// The directory in which we run pub serve .
26- String directory ;
36+ /// Top level directory in which we run the test server. .
37+ String workingDirectory ;
2738
28- /// The path to pass to webdev serve.
39+ /// The path to build and serve.
2940 String pathToServe;
3041
3142 /// The path part of the application URL.
@@ -35,7 +46,8 @@ class TestContext {
3546 {String directory,
3647 this .path = 'hello_world/index.html' ,
3748 this .pathToServe = 'example' }) {
38- this .directory = directory ?? p.relative ('../_test' , from: p.current);
49+ workingDirectory = p.normalize (
50+ p.absolute (directory ?? p.relative ('../_test' , from: p.current)));
3951 }
4052
4153 Future <void > setUp () async {
@@ -48,26 +60,28 @@ class TestContext {
4860 'Could not start ChromeDriver. Is it installed?\n Error: $e ' );
4961 }
5062
51- await Process .run ('pub' , ['get' ], workingDirectory: directory);
52-
53- webdev = await Process .start (
54- 'pub' , ['run' , 'webdev' , 'serve' , '$pathToServe :$port ' ],
55- workingDirectory: directory);
56- webdev.stderr
57- .transform (const Utf8Decoder ())
58- .transform (const LineSplitter ())
59- .listen (print);
60- var assetReadyCompleter = Completer ();
61- webdev.stdout
62- .transform (const Utf8Decoder ())
63- .transform (const LineSplitter ())
64- .listen ((line) {
65- if (line.contains ('$port ' ) && ! assetReadyCompleter.isCompleted) {
66- assetReadyCompleter.complete ();
67- }
68- printOnFailure (line);
69- });
70- await assetReadyCompleter.future.timeout (Duration (seconds: 60 ));
63+ await Process .run ('pub' , ['get' ], workingDirectory: workingDirectory);
64+
65+ daemonClient = await connectClient (
66+ workingDirectory, [], (log) => printOnFailure (log.toString ()));
67+ testServer = await TestServer .start (
68+ 'localhost' ,
69+ port,
70+ daemonPort (workingDirectory),
71+ pathToServe,
72+ ReloadConfiguration .none,
73+ false ,
74+ daemonClient.buildResults,
75+ );
76+ daemonClient.registerBuildTarget (
77+ DefaultBuildTarget ((b) => b..target = pathToServe));
78+ daemonClient.startBuild ();
79+
80+ await daemonClient.buildResults
81+ .firstWhere ((results) => results.results
82+ .any ((result) => result.status == BuildStatus .succeeded))
83+ .timeout (Duration (seconds: 60 ));
84+
7185 appUrl = 'http://localhost:$port /$path ' ;
7286 var debugPort = await findUnusedPort ();
7387 var capabilities = Capabilities .chrome
@@ -108,8 +122,8 @@ class TestContext {
108122 }
109123
110124 Future <Null > tearDown () async {
111- webdev. kill ();
112- await webdev.exitCode ;
125+ await daemonClient. close ();
126+ await testServer. stop () ;
113127 await webDriver? .quit ();
114128 chromeDriver.kill ();
115129 }
0 commit comments