OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library pub_tests; | |
6 | |
7 import 'dart:async'; | |
8 import 'dart:io'; | |
9 | |
10 import 'package:http/http.dart' as http; | |
11 import 'package:scheduled_test/scheduled_process.dart'; | |
12 import 'package:scheduled_test/scheduled_test.dart'; | |
13 | |
14 import '../descriptor.dart' as d; | |
15 import '../test_pub.dart'; | |
16 | |
17 /// The pub process running "pub serve". | |
18 ScheduledProcess _pubServer; | |
19 | |
20 /// The ephemeral port assigned to the running server. | |
21 int _port; | |
22 | |
23 /// Schedules starting the "pub serve" process. | |
24 void startPubServe() { | |
25 // Use port 0 to get an ephemeral port. | |
26 _pubServer = startPub(args: ["serve", "--port=0"]); | |
27 | |
28 _pubServer.nextLine().then((line) { | |
29 var match = new RegExp(r"localhost:(\d+)").firstMatch(line); | |
30 assert(match != null); | |
31 _port = int.parse(match[1]); | |
32 }); | |
nweiz
2013/07/29 20:23:15
You'll still need to use expect(..., completes) so
Bob Nystrom
2013/07/29 21:45:43
Done.
| |
33 } | |
34 | |
35 void endPubServe() { | |
36 _pubServer.kill(); | |
37 } | |
38 | |
39 /// Schedules an HTTP request to the running pub server with [urlPath] and | |
40 /// verifies that it responds with [expected]. | |
41 void requestShouldSucceed(String urlPath, String expected) { | |
42 schedule(() { | |
43 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | |
44 expect(response.body, equals(expected)); | |
45 }); | |
46 }, "request $urlPath"); | |
47 } | |
48 | |
49 /// Schedules an HTTP request to the running pub server with [urlPath] and | |
50 /// verifies that it responds with a 404. | |
51 void requestShould404(String urlPath) { | |
52 schedule(() { | |
53 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | |
54 expect(response.statusCode, equals(404)); | |
55 }); | |
56 }, "request $urlPath"); | |
57 } | |
OLD | NEW |