| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 transform.addOutput(new Asset.fromString(transform.primaryInput.id, | 85 transform.addOutput(new Asset.fromString(transform.primaryInput.id, |
| 86 contents.replaceAllMapped(_tokenRegExp, (match) { | 86 contents.replaceAllMapped(_tokenRegExp, (match) { |
| 87 return 'const TOKEN = "(\${match[1]}, \$TOKEN)";'; | 87 return 'const TOKEN = "(\${match[1]}, \$TOKEN)";'; |
| 88 }))); | 88 }))); |
| 89 }); | 89 }); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 """; | 92 """; |
| 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 /// Unlike [pubServe], this doesn't determine the port number of the server, and |
| 98 /// [dart2js] is `false`, does not compile Dart entrypoints in "web" to | 98 /// so may be used to test for errors in the initialization process. |
| 99 /// JavaScript. | |
| 100 /// | 99 /// |
| 101 /// Returns the `pub serve` process. | 100 /// Returns the `pub serve` process. |
| 102 ScheduledProcess startPubServe({bool shouldGetFirst: false, | 101 ScheduledProcess startPubServe([Iterable<String> args]) { |
| 103 Iterable<String> args}) { | |
| 104 // Use port 0 to get an ephemeral port. | 102 // Use port 0 to get an ephemeral port. |
| 105 var pubArgs = ["serve", "--port=0", "--hostname=127.0.0.1"]; | 103 var pubArgs = ["serve", "--port=0", "--hostname=127.0.0.1", "--force-poll"]; |
| 106 | 104 |
| 107 if (args != null) pubArgs.addAll(args); | 105 if (args != null) pubArgs.addAll(args); |
| 108 | 106 |
| 109 // Dart2js can take a long time to compile dart code, so we increase the | 107 // Dart2js can take a long time to compile dart code, so we increase the |
| 110 // timeout to cope with that. | 108 // timeout to cope with that. |
| 111 currentSchedule.timeout = new Duration(seconds: 15); | 109 currentSchedule.timeout = new Duration(seconds: 15); |
| 112 | 110 |
| 113 _pubServer = startPub(args: pubArgs); | 111 return startPub(args: pubArgs); |
| 112 } |
| 113 |
| 114 /// Schedules starting the "pub serve" process and records its port number for |
| 115 /// future requests. |
| 116 /// |
| 117 /// If [shouldGetFirst] is `true`, validates that pub get is run first. |
| 118 /// |
| 119 /// Returns the `pub serve` process. |
| 120 ScheduledProcess pubServe({bool shouldGetFirst: false, |
| 121 Iterable<String> args}) { |
| 122 _pubServer = startPubServe(args); |
| 114 | 123 |
| 115 currentSchedule.onComplete.schedule(() { | 124 currentSchedule.onComplete.schedule(() { |
| 116 if (_webSocket != null) { | 125 if (_webSocket != null) { |
| 117 _webSocket.close(); | 126 _webSocket.close(); |
| 118 _webSocket = null; | 127 _webSocket = null; |
| 119 _webSocketBroadcastStream = null; | 128 _webSocketBroadcastStream = null; |
| 120 } | 129 } |
| 121 }); | 130 }); |
| 122 | 131 |
| 123 if (shouldGetFirst) { | 132 if (shouldGetFirst) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 /// socket. It omitted, request is JSON encoded to a string first. | 231 /// socket. It omitted, request is JSON encoded to a string first. |
| 223 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 232 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
| 224 schedule(() => _ensureWebSocket().then((_) { | 233 schedule(() => _ensureWebSocket().then((_) { |
| 225 if (encodeRequest) request = JSON.encode(request); | 234 if (encodeRequest) request = JSON.encode(request); |
| 226 _webSocket.add(request); | 235 _webSocket.add(request); |
| 227 return _webSocketBroadcastStream.first.then((value) { | 236 return _webSocketBroadcastStream.first.then((value) { |
| 228 expect(JSON.decode(value), expectation); | 237 expect(JSON.decode(value), expectation); |
| 229 }); | 238 }); |
| 230 }), "send $request to web socket and expect reply that $expectation"); | 239 }), "send $request to web socket and expect reply that $expectation"); |
| 231 } | 240 } |
| OLD | NEW |