Chromium Code Reviews| 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 |
| 11 import 'package:http/http.dart' as http; | 11 import 'package:http/http.dart' as http; |
| 12 import 'package:path/path.dart' as p; | 12 import 'package:path/path.dart' as p; |
| 13 import 'package:scheduled_test/scheduled_process.dart'; | 13 import 'package:scheduled_test/scheduled_process.dart'; |
| 14 import 'package:scheduled_test/scheduled_stream.dart'; | |
| 14 import 'package:scheduled_test/scheduled_test.dart'; | 15 import 'package:scheduled_test/scheduled_test.dart'; |
| 15 | 16 |
| 16 import '../test_pub.dart'; | 17 import '../test_pub.dart'; |
| 17 | 18 |
| 18 /// The pub process running "pub serve". | 19 /// The pub process running "pub serve". |
| 19 ScheduledProcess _pubServer; | 20 ScheduledProcess _pubServer; |
| 20 | 21 |
| 21 /// The ephemeral port assigned to the running server. | 22 /// The ephemeral port assigned to the running server. |
| 22 int _port; | 23 int _port; |
| 23 | 24 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 127 |
| 127 currentSchedule.onComplete.schedule(() { | 128 currentSchedule.onComplete.schedule(() { |
| 128 if (_webSocket != null) { | 129 if (_webSocket != null) { |
| 129 _webSocket.close(); | 130 _webSocket.close(); |
| 130 _webSocket = null; | 131 _webSocket = null; |
| 131 _webSocketBroadcastStream = null; | 132 _webSocketBroadcastStream = null; |
| 132 } | 133 } |
| 133 }); | 134 }); |
| 134 | 135 |
| 135 if (shouldGetFirst) { | 136 if (shouldGetFirst) { |
| 136 expect(_pubServer.nextLine(), | 137 _pubServer.stdout.expect(anyOf( |
| 137 completion(anyOf( | 138 startsWith("Your pubspec has changed"), |
| 138 startsWith("Your pubspec has changed"), | 139 startsWith("You don't have a lockfile"), |
| 139 startsWith("You don't have a lockfile"), | 140 startsWith("You are missing some dependencies"))); |
| 140 startsWith("You are missing some dependencies")))); | 141 _pubServer.stdout.expect(startsWith("Resolving dependencies...")); |
| 141 expect(_pubServer.nextLine(), | |
| 142 completion(startsWith("Resolving dependencies..."))); | |
| 143 | |
| 144 for (var i = 0; i < numDownloads; i++) { | 142 for (var i = 0; i < numDownloads; i++) { |
| 145 expect(_pubServer.nextLine(), | 143 _pubServer.stdout.expect(startsWith("Downloading")); |
|
Bob Nystrom
2014/02/14 17:55:02
I hacked in the numDownloads stuff because at the
nweiz
2014/02/18 22:01:10
Done.
| |
| 146 completion(startsWith("Downloading"))); | |
| 147 } | 144 } |
| 148 | 145 |
| 149 expect(_pubServer.nextLine(), | 146 _pubServer.stdout.expect(equals("Got dependencies!")); |
| 150 completion(equals("Got dependencies!"))); | |
| 151 } | 147 } |
| 152 | 148 |
| 153 expect(_pubServer.nextLine().then(_parsePort), completes); | 149 expect(schedule(() => _pubServer.stdout.next()).then(_parsePort), completes); |
| 154 return _pubServer; | 150 return _pubServer; |
| 155 } | 151 } |
| 156 | 152 |
| 157 /// Parses the port number from the "Serving blah on 127.0.0.1:1234" line | 153 /// Parses the port number from the "Serving blah on 127.0.0.1:1234" line |
| 158 /// printed by pub serve. | 154 /// printed by pub serve. |
| 159 void _parsePort(String line) { | 155 void _parsePort(String line) { |
| 160 var match = new RegExp(r"127\.0\.0\.1:(\d+)").firstMatch(line); | 156 var match = new RegExp(r"127\.0\.0\.1:(\d+)").firstMatch(line); |
| 161 assert(match != null); | 157 assert(match != null); |
| 162 _port = int.parse(match[1]); | 158 _port = int.parse(match[1]); |
| 163 } | 159 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 expect(response.statusCode, equals(405)); | 212 expect(response.statusCode, equals(405)); |
| 217 }); | 213 }); |
| 218 }, "request $urlPath"); | 214 }, "request $urlPath"); |
| 219 } | 215 } |
| 220 | 216 |
| 221 /// Reads lines from pub serve's stdout until it prints the build success | 217 /// Reads lines from pub serve's stdout until it prints the build success |
| 222 /// message. | 218 /// message. |
| 223 /// | 219 /// |
| 224 /// The schedule will not proceed until the output is found. If not found, it | 220 /// The schedule will not proceed until the output is found. If not found, it |
| 225 /// will eventually time out. | 221 /// will eventually time out. |
| 226 void waitForBuildSuccess() { | 222 void waitForBuildSuccess() => |
| 227 nextLine() { | 223 _pubServer.stdout.expect(consumeThrough(contains("successfully"))); |
|
Bob Nystrom
2014/02/14 17:55:02
\o/
| |
| 228 return _pubServer.nextLine().then((line) { | |
| 229 if (line.contains("successfully")) return null; | |
| 230 | |
| 231 // This line wasn't it, so ignore it and keep trying. | |
| 232 return nextLine(); | |
| 233 }); | |
| 234 } | |
| 235 | |
| 236 schedule(nextLine); | |
| 237 } | |
| 238 | 224 |
| 239 /// Schedules opening a web socket connection to the currently running pub | 225 /// Schedules opening a web socket connection to the currently running pub |
| 240 /// serve. | 226 /// serve. |
| 241 Future _ensureWebSocket() { | 227 Future _ensureWebSocket() { |
| 242 // Use the existing one if already connected. | 228 // Use the existing one if already connected. |
| 243 if (_webSocket != null) return new Future.value(); | 229 if (_webSocket != null) return new Future.value(); |
| 244 | 230 |
| 245 // Server should already be running. | 231 // Server should already be running. |
| 246 assert(_pubServer != null); | 232 assert(_pubServer != null); |
| 247 assert(_port != null); | 233 assert(_port != null); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 261 /// socket. It omitted, request is JSON encoded to a string first. | 247 /// socket. It omitted, request is JSON encoded to a string first. |
| 262 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 248 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
| 263 schedule(() => _ensureWebSocket().then((_) { | 249 schedule(() => _ensureWebSocket().then((_) { |
| 264 if (encodeRequest) request = JSON.encode(request); | 250 if (encodeRequest) request = JSON.encode(request); |
| 265 _webSocket.add(request); | 251 _webSocket.add(request); |
| 266 return _webSocketBroadcastStream.first.then((value) { | 252 return _webSocketBroadcastStream.first.then((value) { |
| 267 expect(JSON.decode(value), expectation); | 253 expect(JSON.decode(value), expectation); |
| 268 }); | 254 }); |
| 269 }), "send $request to web socket and expect reply that $expectation"); | 255 }), "send $request to web socket and expect reply that $expectation"); |
| 270 } | 256 } |
| OLD | NEW |