| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub_tests; | 5 library pub_tests; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 if (args != null) pubArgs.addAll(args); | 162 if (args != null) pubArgs.addAll(args); |
| 163 | 163 |
| 164 if (createWebDir) d.dir(appPath, [d.dir("web")]).create(); | 164 if (createWebDir) d.dir(appPath, [d.dir("web")]).create(); |
| 165 return startPub(args: pubArgs); | 165 return startPub(args: pubArgs); |
| 166 } | 166 } |
| 167 | 167 |
| 168 /// Schedules starting the "pub serve" process and records its port number for | 168 /// Schedules starting the "pub serve" process and records its port number for |
| 169 /// future requests. | 169 /// future requests. |
| 170 /// | 170 /// |
| 171 /// If [shouldGetFirst] is `true`, validates that pub get is run first. | |
| 172 /// | |
| 173 /// If [createWebDir] is `true`, creates a `web/` directory if one doesn't exist | 171 /// If [createWebDir] is `true`, creates a `web/` directory if one doesn't exist |
| 174 /// so pub doesn't complain about having nothing to serve. | 172 /// so pub doesn't complain about having nothing to serve. |
| 175 /// | 173 /// |
| 176 /// Returns the `pub serve` process. | 174 /// Returns the `pub serve` process. |
| 177 ScheduledProcess pubServe({bool shouldGetFirst: false, bool createWebDir: true, | 175 ScheduledProcess pubServe({bool createWebDir: true, Iterable<String> args}) { |
| 178 Iterable<String> args}) { | |
| 179 _pubServer = startPubServe(args: args, createWebDir: createWebDir); | 176 _pubServer = startPubServe(args: args, createWebDir: createWebDir); |
| 180 _portsCompleter = new Completer(); | 177 _portsCompleter = new Completer(); |
| 181 | 178 |
| 182 currentSchedule.onComplete.schedule(() { | 179 currentSchedule.onComplete.schedule(() { |
| 183 _portsCompleter = null; | 180 _portsCompleter = null; |
| 184 _ports.clear(); | 181 _ports.clear(); |
| 185 | 182 |
| 186 if (_webSocket != null) { | 183 if (_webSocket != null) { |
| 187 _webSocket.close(); | 184 _webSocket.close(); |
| 188 _webSocket = null; | 185 _webSocket = null; |
| 189 _webSocketBroadcastStream = null; | 186 _webSocketBroadcastStream = null; |
| 190 } | 187 } |
| 191 }); | 188 }); |
| 192 | 189 |
| 193 if (shouldGetFirst) { | |
| 194 _pubServer.stdout.expect(consumeThrough(anyOf([ | |
| 195 "Got dependencies!", | |
| 196 matches(new RegExp(r"^Changed \d+ dependenc")) | |
| 197 ]))); | |
| 198 } | |
| 199 | |
| 200 _pubServer.stdout.expect(startsWith("Loading source assets...")); | 190 _pubServer.stdout.expect(startsWith("Loading source assets...")); |
| 201 _pubServer.stdout.expect(consumeWhile(matches("Loading .* transformers..."))); | 191 _pubServer.stdout.expect(consumeWhile(matches("Loading .* transformers..."))); |
| 202 | 192 |
| 203 _pubServer.stdout.expect(predicate(_parseAdminPort)); | 193 _pubServer.stdout.expect(predicate(_parseAdminPort)); |
| 204 | 194 |
| 205 // The server should emit one or more ports. | 195 // The server should emit one or more ports. |
| 206 _pubServer.stdout.expect( | 196 _pubServer.stdout.expect( |
| 207 consumeWhile(predicate(_parsePort, 'emits server url'))); | 197 consumeWhile(predicate(_parsePort, 'emits server url'))); |
| 208 schedule(() { | 198 schedule(() { |
| 209 expect(_ports, isNot(isEmpty)); | 199 expect(_ports, isNot(isEmpty)); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 /// included. Unlike [getServerUrl], this should only be called after the ports | 479 /// included. Unlike [getServerUrl], this should only be called after the ports |
| 490 /// are known. | 480 /// are known. |
| 491 String _getServerUrlSync([String root, String path]) { | 481 String _getServerUrlSync([String root, String path]) { |
| 492 if (root == null) root = 'web'; | 482 if (root == null) root = 'web'; |
| 493 expect(_ports, contains(root)); | 483 expect(_ports, contains(root)); |
| 494 var url = "http://localhost:${_ports[root]}"; | 484 var url = "http://localhost:${_ports[root]}"; |
| 495 if (path != null) url = "$url/$path"; | 485 if (path != null) url = "$url/$path"; |
| 496 return url; | 486 return url; |
| 497 } | 487 } |
| 498 | 488 |
| OLD | NEW |