OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library pub_tests; | |
6 | |
7 import 'package:path/path.dart' as p; | |
8 | |
9 import '../../../lib/src/io.dart'; | |
10 import '../../descriptor.dart' as d; | |
11 import '../../test_pub.dart'; | |
12 import '../utils.dart'; | |
13 | |
14 main() { | |
15 // TODO(rnystrom): Split into independent tests. | |
16 initConfig(); | |
17 integration("pathToUrls converts asset ids to matching URL paths", () { | |
18 d.dir( | |
19 "foo", | |
20 [ | |
21 d.libPubspec("foo", "1.0.0"), | |
22 d.dir("lib", [d.file("foo.dart", "foo() => null;")])]).create(); | |
23 | |
24 d.dir(appPath, [d.appPubspec({ | |
25 "foo": { | |
26 "path": "../foo" | |
27 } | |
28 }), | |
29 d.dir( | |
30 "test", | |
31 [d.file("index.html", "<body>"), d.dir("sub", [d.file("bar.html",
"bar"),])]), | |
32 d.dir("lib", [d.file("app.dart", "app() => null;")]), | |
33 d.dir( | |
34 "web", | |
35 [d.file("index.html", "<body>"), d.dir("sub", [d.file("bar.html",
"bar"),])]), | |
36 d.dir("randomdir", [d.file("index.html", "<body>")])]).create(); | |
37 | |
38 pubServe(args: ["test", "web", "randomdir"], shouldGetFirst: true); | |
39 | |
40 // Paths in web/. | |
41 expectWebSocketResult("pathToUrls", { | |
42 "path": p.join("web", "index.html") | |
43 }, { | |
44 "urls": [getServerUrl("web", "index.html")] | |
45 }); | |
46 | |
47 expectWebSocketResult("pathToUrls", { | |
48 "path": p.join("web", "sub", "bar.html") | |
49 }, { | |
50 "urls": [getServerUrl("web", "sub/bar.html")] | |
51 }); | |
52 | |
53 // Paths in test/. | |
54 expectWebSocketResult("pathToUrls", { | |
55 "path": p.join("test", "index.html") | |
56 }, { | |
57 "urls": [getServerUrl("test", "index.html")] | |
58 }); | |
59 | |
60 expectWebSocketResult("pathToUrls", { | |
61 "path": p.join("test", "sub", "bar.html") | |
62 }, { | |
63 "urls": [getServerUrl("test", "sub/bar.html")] | |
64 }); | |
65 | |
66 // A non-default directory. | |
67 expectWebSocketResult("pathToUrls", { | |
68 "path": p.join("randomdir", "index.html") | |
69 }, { | |
70 "urls": [getServerUrl("randomdir", "index.html")] | |
71 }); | |
72 | |
73 // A path in lib/. | |
74 expectWebSocketResult("pathToUrls", { | |
75 "path": p.join("lib", "app.dart") | |
76 }, { | |
77 "urls": [ | |
78 getServerUrl("test", "packages/myapp/app.dart"), | |
79 getServerUrl("web", "packages/myapp/app.dart"), | |
80 getServerUrl("randomdir", "packages/myapp/app.dart")] | |
81 }); | |
82 | |
83 // A path to this package in packages/. | |
84 expectWebSocketResult("pathToUrls", { | |
85 "path": p.join("packages", "myapp", "app.dart") | |
86 }, { | |
87 "urls": [ | |
88 getServerUrl("test", "packages/myapp/app.dart"), | |
89 getServerUrl("web", "packages/myapp/app.dart"), | |
90 getServerUrl("randomdir", "packages/myapp/app.dart")] | |
91 }); | |
92 | |
93 // A path to another package in packages/. | |
94 expectWebSocketResult("pathToUrls", { | |
95 "path": p.join("packages", "foo", "foo.dart") | |
96 }, { | |
97 "urls": [ | |
98 getServerUrl("test", "packages/foo/foo.dart"), | |
99 getServerUrl("web", "packages/foo/foo.dart"), | |
100 getServerUrl("randomdir", "packages/foo/foo.dart")] | |
101 }); | |
102 | |
103 // A relative path to another package's lib/ directory. | |
104 expectWebSocketResult("pathToUrls", { | |
105 "path": p.join("..", "foo", "lib", "foo.dart") | |
106 }, { | |
107 "urls": [ | |
108 getServerUrl("test", "packages/foo/foo.dart"), | |
109 getServerUrl("web", "packages/foo/foo.dart"), | |
110 getServerUrl("randomdir", "packages/foo/foo.dart")] | |
111 }); | |
112 | |
113 // Note: Using canonicalize here because pub gets the path to the | |
114 // entrypoint package from the working directory, which has had symlinks | |
115 // resolve. On Mac, "/tmp" is actually a symlink to "/private/tmp", so we | |
116 // need to accomodate that. | |
117 | |
118 // An absolute path to another package's lib/ directory. | |
119 expectWebSocketResult("pathToUrls", { | |
120 "path": canonicalize(p.join(sandboxDir, "foo", "lib", "foo.dart")) | |
121 }, { | |
122 "urls": [ | |
123 getServerUrl("test", "packages/foo/foo.dart"), | |
124 getServerUrl("web", "packages/foo/foo.dart"), | |
125 getServerUrl("randomdir", "packages/foo/foo.dart")] | |
126 }); | |
127 | |
128 endPubServe(); | |
129 }); | |
130 } | |
OLD | NEW |