| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2014, 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 | 8 |
| 9 import 'package:scheduled_test/scheduled_test.dart'; | 9 import 'package:scheduled_test/scheduled_test.dart'; |
| 10 | 10 |
| 11 import '../../descriptor.dart' as d; | 11 import '../../descriptor.dart' as d; |
| 12 import '../../test_pub.dart'; | 12 import '../../test_pub.dart'; |
| 13 import '../utils.dart'; | 13 import '../utils.dart'; |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 initConfig(); | 16 initConfig(); |
| 17 integration("binds a directory to a new port and immediately unbinds that " | 17 integration( |
| 18 "directory", () { | 18 "binds a directory to a new port and immediately unbinds that " "directory
", |
| 19 d.dir(appPath, [ | 19 () { |
| 20 d.appPubspec(), | 20 d.dir( |
| 21 d.dir("test", [ | 21 appPath, |
| 22 d.file("index.html", "<test body>") | 22 [ |
| 23 ]), | 23 d.appPubspec(), |
| 24 d.dir("web", [ | 24 d.dir("test", [d.file("index.html", "<test body>")]), |
| 25 d.file("index.html", "<body>") | 25 d.dir("web", [d.file("index.html", "<body>")])]).create(); |
| 26 ]) | |
| 27 ]).create(); | |
| 28 | 26 |
| 29 pubServe(args: ["web"]); | 27 pubServe(args: ["web"]); |
| 30 | 28 |
| 31 // We call [webSocketRequest] outside of the [schedule] call below because | 29 // We call [webSocketRequest] outside of the [schedule] call below because |
| 32 // we need it to schedule the sending of the request to guarantee that the | 30 // we need it to schedule the sending of the request to guarantee that the |
| 33 // serve is sent before the unserve. | 31 // serve is sent before the unserve. |
| 34 var serveRequest = webSocketRequest("serveDirectory", {"path": "test"}); | 32 var serveRequest = webSocketRequest("serveDirectory", { |
| 35 var unserveRequest = webSocketRequest("unserveDirectory", {"path": "test"}); | 33 "path": "test" |
| 34 }); |
| 35 var unserveRequest = webSocketRequest("unserveDirectory", { |
| 36 "path": "test" |
| 37 }); |
| 36 | 38 |
| 37 schedule(() { | 39 schedule(() { |
| 38 return Future.wait([serveRequest, unserveRequest]).then((results) { | 40 return Future.wait([serveRequest, unserveRequest]).then((results) { |
| 39 expect(results[0], contains("result")); | 41 expect(results[0], contains("result")); |
| 40 expect(results[1], contains("result")); | 42 expect(results[1], contains("result")); |
| 41 // These results should be equal since "serveDirectory" returns the URL | 43 // These results should be equal since "serveDirectory" returns the URL |
| 42 // of the new server and "unserveDirectory" returns the URL of the | 44 // of the new server and "unserveDirectory" returns the URL of the |
| 43 // server that was turned off. We're asserting that the same server was | 45 // server that was turned off. We're asserting that the same server was |
| 44 // both started and stopped. | 46 // both started and stopped. |
| 45 expect(results[0]["result"]["url"], matches(r"http://localhost:\d+")); | 47 expect(results[0]["result"]["url"], matches(r"http://localhost:\d+")); |
| 46 expect(results[0]["result"], equals(results[1]["result"])); | 48 expect(results[0]["result"], equals(results[1]["result"])); |
| 47 }); | 49 }); |
| 48 }); | 50 }); |
| 49 | 51 |
| 50 endPubServe(); | 52 endPubServe(); |
| 51 }); | 53 }); |
| 52 } | 54 } |
| OLD | NEW |