| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 /// Schedules starting the "pub serve" process. | 95 /// Schedules starting the "pub serve" process. |
| 96 /// | 96 /// |
| 97 /// If [shouldGetFirst] is `true`, validates that pub get is run first. If | 97 /// If [shouldGetFirst] is `true`, validates that pub get is run first. If |
| 98 /// [dart2js] is `false`, does not compile Dart entrypoints in "web" to | 98 /// [dart2js] is `false`, does not compile Dart entrypoints in "web" to |
| 99 /// JavaScript. | 99 /// JavaScript. |
| 100 /// | 100 /// |
| 101 /// Returns the `pub serve` process. | 101 /// Returns the `pub serve` process. |
| 102 ScheduledProcess startPubServe({bool shouldGetFirst: false, | 102 ScheduledProcess startPubServe({bool shouldGetFirst: false, |
| 103 bool dart2js: true}) { | 103 Iterable<String> args}) { |
| 104 // Use port 0 to get an ephemeral port. | 104 // Use port 0 to get an ephemeral port. |
| 105 var args = ["serve", "--port=0", "--hostname=127.0.0.1"]; | 105 var pubArgs = ["serve", "--port=0", "--hostname=127.0.0.1"]; |
| 106 | 106 |
| 107 if (!dart2js) args.add("--no-dart2js"); | 107 if (args != null) pubArgs.addAll(args); |
| 108 | 108 |
| 109 // Dart2js can take a long time to compile dart code, so we increase the | 109 // Dart2js can take a long time to compile dart code, so we increase the |
| 110 // timeout to cope with that. | 110 // timeout to cope with that. |
| 111 if (dart2js) { | 111 currentSchedule.timeout = new Duration(seconds: 15); |
| 112 currentSchedule.timeout = new Duration(seconds: 15); | |
| 113 } | |
| 114 | 112 |
| 115 _pubServer = startPub(args: args); | 113 _pubServer = startPub(args: pubArgs); |
| 116 | 114 |
| 117 currentSchedule.onComplete.schedule(() { | 115 currentSchedule.onComplete.schedule(() { |
| 118 if (_webSocket != null) { | 116 if (_webSocket != null) { |
| 119 _webSocket.close(); | 117 _webSocket.close(); |
| 120 _webSocket = null; | 118 _webSocket = null; |
| 121 _webSocketBroadcastStream = null; | 119 _webSocketBroadcastStream = null; |
| 122 } | 120 } |
| 123 }); | 121 }); |
| 124 | 122 |
| 125 if (shouldGetFirst) { | 123 if (shouldGetFirst) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 /// socket. It omitted, request is JSON encoded to a string first. | 222 /// socket. It omitted, request is JSON encoded to a string first. |
| 225 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 223 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
| 226 schedule(() => _ensureWebSocket().then((_) { | 224 schedule(() => _ensureWebSocket().then((_) { |
| 227 if (encodeRequest) request = JSON.encode(request); | 225 if (encodeRequest) request = JSON.encode(request); |
| 228 _webSocket.add(request); | 226 _webSocket.add(request); |
| 229 return _webSocketBroadcastStream.first.then((value) { | 227 return _webSocketBroadcastStream.first.then((value) { |
| 230 expect(JSON.decode(value), expectation); | 228 expect(JSON.decode(value), expectation); |
| 231 }); | 229 }); |
| 232 }), "send $request to web socket and expect reply that $expectation"); | 230 }), "send $request to web socket and expect reply that $expectation"); |
| 233 } | 231 } |
| OLD | NEW |