source: Dev/trunk/src/client/dojo/tests/_base/loader/moduleIds.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 9.4 KB
Line 
1define(["doh", "dojo", "dojo/_base/url"], function(doh, dojo){
2
3        var compactPath = function(path){
4                var
5                        result= [],
6                        segment, lastSegment;
7            path= path.split("/");
8                while(path.length){
9                        segment= path.shift();
10                        if(segment==".." && result.length && lastSegment!=".."){
11                                result.pop();
12                        }else if(segment!="."){
13                                result.push(lastSegment= segment);
14                        } // else ignore "."
15                }
16                return result.join("/");
17        };
18
19        doh.register("dojo.tests._base._loader.modulesIds", [
20                function compactPath(t){
21                        var compactPath = require.compactPath;
22                        t.is(compactPath("../../dojo/../../mytests"), "../../../mytests");
23                        t.is(compactPath("module"), "module");
24                        t.is(compactPath("a/./b"), "a/b");
25                        t.is(compactPath("a/../b"), "b");
26                        t.is(compactPath("a/./b/./c/./d"), "a/b/c/d");
27                        t.is(compactPath("a/../b/../c/../d"), "d");
28                        t.is(compactPath("a/b/c/../../d"), "a/d");
29                        t.is(compactPath("a/b/c/././d"), "a/b/c/d");
30                        t.is(compactPath("./a/b"), "a/b");
31                        t.is(compactPath("../a/b"), "../a/b");
32                        t.is(compactPath(""), "");
33                },
34
35                function testModuleIds(t){
36                        require({
37                                packages:[{
38                                        // canonical...
39                                        name:"pack1",
40                                        location:"../packages/pack1Root"
41                                }, {
42                                        // nonstandard main
43                                        name:"pack2",
44                                        main:"pack2Main",
45                                        location:"/pack2Root"
46                                }, {
47                                        // nonstandard main
48                                        name:"pack3",
49                                        main:"public/main",
50                                        location:"/pack3Root"
51                                }]
52                        });
53
54                        function get(mid, refmod){
55                                return require.getModuleInfo(mid, refmod, require.packs, require.modules, "../../dojo/", require.mapProgs, require.pathsMapProg, 1);
56                        }
57
58                        function check(result, expectedPid, expectedMidSansPid, expectedUrl){
59                                t.is(result.pid, expectedPid);
60                                t.is(result.mid, expectedPid + "/" + expectedMidSansPid);
61                                t.is(result.url, expectedUrl + ".js");
62                        }
63
64            // non-relative module id resolution...
65
66                        var pack1Root= "../../packages/pack1Root/";
67
68                        // the various mains...
69                        check(get("pack1"), "pack1", "main", pack1Root + "main");
70                        check(get("pack2"), "pack2", "pack2Main", "/pack2Root/pack2Main");
71                        check(get("pack3"), "pack3", "public/main", "/pack3Root/public/main");
72
73                        // modules...
74                        check(get("pack1/myModule"), "pack1", "myModule", pack1Root + "myModule");
75                        check(get("pack2/myModule"), "pack2", "myModule", "/pack2Root/myModule");
76                        check(get("pack3/myModule"), "pack3", "myModule", "/pack3Root/myModule");
77
78                        // relative module id resolution; relative to module in top-level
79                        var refmod= {mid:"pack1/main", pack:require.packs.pack1};
80                        check(get(".", refmod), "pack1", "main", pack1Root + "main");
81                        check(get("./myModule", refmod), "pack1", "myModule", pack1Root + "myModule");
82                        check(get("./myModule/mySubmodule", refmod), "pack1", "myModule/mySubmodule", pack1Root + "myModule/mySubmodule");
83
84                        // relative module id resolution; relative to module
85                        refmod= {mid:"pack1/sub/publicModule", pack:require.packs.pack1};
86                        check(get(".", refmod), "pack1", "sub", pack1Root + "sub");
87                        check(get("./myModule", refmod), "pack1", "sub/myModule", pack1Root + "sub/myModule");
88                        check(get("..", refmod), "pack1", "main", pack1Root + "main");
89                        check(get("../myModule", refmod), "pack1", "myModule", pack1Root + "myModule");
90                        check(get("../util/myModule", refmod), "pack1", "util/myModule", pack1Root + "util/myModule");
91                },
92
93                function baseUrl(t){
94                        var originalBaseUrl = dojo.config["baseUrl"] || "./";
95
96                        t.assertEqual(originalBaseUrl, dojo.baseUrl);
97                },
98
99                function moduleUrl(t){
100                        var expected = require.toUrl("dojo/tests/myTest.html");
101                        t.is(null, dojo.moduleUrl());
102                        t.is(null, dojo.moduleUrl(null));
103                        t.is(null, dojo.moduleUrl(null, "myTest.html"));
104                        // note we expect a trailing slash
105                        t.is(expected.substring(0, expected.length - 11), dojo.moduleUrl("dojo.tests"));
106                        t.is(expected, dojo.moduleUrl("dojo.tests", "myTest.html"));
107                },
108
109                function modulePaths(t){
110                        dojo.registerModulePath("mycoolmod", "../some/path/mycoolpath");
111                        dojo.registerModulePath("mycoolmod.widget", "http://some.domain.com/another/path/mycoolpath/widget");
112
113                        t.assertEqual(compactPath(require.baseUrl + "../some/path/mycoolpath/util/"), dojo.moduleUrl("mycoolmod.util"));
114                        t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/", dojo.moduleUrl("mycoolmod.widget"));
115                        t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/thingy/", dojo.moduleUrl("mycoolmod.widget.thingy"));
116                },
117
118                function moduleUrls(t){
119                        dojo.registerModulePath("mycoolmod", "some/path/mycoolpath");
120                        dojo.registerModulePath("mycoolmod2", "/some/path/mycoolpath2");
121                        dojo.registerModulePath("mycoolmod.widget", "http://some.domain.com/another/path/mycoolpath/widget");
122                        dojo.registerModulePath("ipv4.widget", "http://ipv4user:ipv4passwd@some.domain.com:2357/another/path/ipv4/widget");
123                        dojo.registerModulePath("ipv6.widget", "ftp://ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113/another/path/ipv6/widget");
124                        dojo.registerModulePath("ipv6.widget2", "https://[0:0:0:0:0:1]/another/path/ipv6/widget2");
125
126
127                        var basePrefix = require.baseUrl;
128
129                        t.assertEqual(compactPath(basePrefix + "some/path/mycoolpath/my/favorite.html"),
130                                dojo.moduleUrl("mycoolmod", "my/favorite.html"));
131                        t.assertEqual(compactPath(basePrefix + "some/path/mycoolpath/my/favorite.html"),
132                                dojo.moduleUrl("mycoolmod.my", "favorite.html"));
133
134                        t.assertEqual("/some/path/mycoolpath2/my/favorite.html",
135                                dojo.moduleUrl("mycoolmod2", "my/favorite.html"));
136                        t.assertEqual("/some/path/mycoolpath2/my/favorite.html",
137                                dojo.moduleUrl("mycoolmod2.my", "favorite.html"));
138
139                        t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/my/favorite.html",
140                                dojo.moduleUrl("mycoolmod.widget", "my/favorite.html"));
141                        t.assertEqual("http://some.domain.com/another/path/mycoolpath/widget/my/favorite.html",
142                                dojo.moduleUrl("mycoolmod.widget.my", "favorite.html"));
143
144                        // individual component testing
145                        t.assertEqual("http://ipv4user:ipv4passwd@some.domain.com:2357/another/path/ipv4/widget/components.html",
146                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).uri);
147                        t.assertEqual("http",
148                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).scheme);
149                        t.assertEqual("ipv4user:ipv4passwd@some.domain.com:2357",
150                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).authority);
151                        t.assertEqual("ipv4user",
152                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).user);
153                        t.assertEqual("ipv4passwd",
154                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).password);
155                        t.assertEqual("some.domain.com",
156                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).host);
157                        t.assertEqual("2357",
158                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html"))).port);
159                        t.assertEqual("/another/path/ipv4/widget/components.html",
160                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html?query"))).path);
161                        t.assertEqual("q=somequery",
162                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html?q=somequery"))).query);
163                        t.assertEqual("fragment",
164                                (new dojo._Url(dojo.moduleUrl("ipv4.widget", "components.html#fragment"))).fragment);
165
166                        t.assertEqual("ftp://ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113/another/path/ipv6/widget/components.html",
167                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).uri);
168                        t.assertEqual("ftp",
169                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).scheme);
170                        t.assertEqual("ipv6user:ipv6passwd@[::2001:0db8:3c4d:0015:0:0:abcd:ef12]:1113",
171                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).authority);
172                        t.assertEqual("ipv6user",
173                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).user);
174                        t.assertEqual("ipv6passwd",
175                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).password);
176                        t.assertEqual("::2001:0db8:3c4d:0015:0:0:abcd:ef12",
177                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).host);
178                        t.assertEqual("1113",
179                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html"))).port);
180                        t.assertEqual("/another/path/ipv6/widget/components.html",
181                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?query"))).path);
182                        t.assertEqual("somequery",
183                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?somequery"))).query);
184                        t.assertEqual("somefragment",
185                                (new dojo._Url(dojo.moduleUrl("ipv6.widget", "components.html?somequery#somefragment"))).fragment);
186
187                        t.assertEqual("https://[0:0:0:0:0:1]/another/path/ipv6/widget2/components.html",
188                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).uri);
189                        t.assertEqual("https",
190                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).scheme);
191                        t.assertEqual("[0:0:0:0:0:1]",
192                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).authority);
193                        t.assertEqual(null,
194                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).user);
195                        t.assertEqual(null,
196                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).password);
197                        t.assertEqual("0:0:0:0:0:1",
198                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).host);
199                        t.assertEqual(null,
200                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).port);
201                        t.assertEqual("/another/path/ipv6/widget2/components.html",
202                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).path);
203                        t.assertEqual(null,
204                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).query);
205                        t.assertEqual(null,
206                                (new dojo._Url(dojo.moduleUrl("ipv6.widget2", "components.html"))).fragment);
207                }
208        ]);
209});
210
Note: See TracBrowser for help on using the repository browser.