1 | (function(){ |
---|
2 | var |
---|
3 | boot = |
---|
4 | // zero to many scripts to load a configuration and/or loader. |
---|
5 | // i.e. path-to-util/doh/runner.html?boots=path-to/config.js,path-to/require.js |
---|
6 | ["../../dojo/dojo.js"], |
---|
7 | |
---|
8 | standardDojoBoot = boot, |
---|
9 | |
---|
10 | test = |
---|
11 | // zero to many AMD modules and/or URLs to load; provided by csv URL query parameter="test" |
---|
12 | // For example, the URL... |
---|
13 | // |
---|
14 | // path-to-util/doh/runner.html?test=doh/selfTest,my/path/test.js |
---|
15 | // |
---|
16 | // ...will load... |
---|
17 | // |
---|
18 | // * the AMD module doh/selfTest |
---|
19 | // * the plain old Javascript resource my/path/test.js |
---|
20 | // |
---|
21 | ["dojo/tests/module"], |
---|
22 | |
---|
23 | paths = |
---|
24 | // zero to many path items to pass to the AMD loader; provided by semicolon separated values |
---|
25 | // for URL query parameter="paths"; each path item has the form <from-path>,<to-path> |
---|
26 | // i.e. path-to-util/doh/runner.html?paths=my/from/path,my/to/path;my/from/path2,my/to/path2 |
---|
27 | {}, |
---|
28 | |
---|
29 | dohPlugins = |
---|
30 | // Semicolon separated list of files to load before the tests. |
---|
31 | // Idea is to override aspects of DOH for reporting purposes. |
---|
32 | "", |
---|
33 | |
---|
34 | breakOnError = |
---|
35 | // boolean; instructs doh to call the debugger upon a test failures; this can be helpful when |
---|
36 | // trying to isolate exactly where the test failed |
---|
37 | false, |
---|
38 | |
---|
39 | async = |
---|
40 | // boolean; config require.async==true before loading boot; this will have the effect of making |
---|
41 | // version 1.7+ dojo bootstrap/loader operating in async mode |
---|
42 | false, |
---|
43 | |
---|
44 | sandbox = |
---|
45 | // boolean; use a loader configuration that sandboxes the dojo and dojox objects used by doh |
---|
46 | false, |
---|
47 | |
---|
48 | trim = function(text){ |
---|
49 | if(text instanceof Array){ |
---|
50 | for (var result= [], i= 0; i<text.length; i++) { |
---|
51 | result.push(trim(text[i])); |
---|
52 | } |
---|
53 | return result; |
---|
54 | }else{ |
---|
55 | return text.match(/[^\s]*/)[0]; |
---|
56 | } |
---|
57 | }; |
---|
58 | |
---|
59 | qstr = window.location.search.substr(1); |
---|
60 | |
---|
61 | if(qstr.length){ |
---|
62 | for(var qparts = qstr.split("&"), x = 0; x < qparts.length; x++){ |
---|
63 | var tp = qparts[x].split("="), name=tp[0], value=(tp[1]||"").replace(/[<>"':\(\)]/g, ""); // replace() to avoid XSS attack |
---|
64 | //Avoid URLs that use the same protocol but on other domains, for security reasons. |
---|
65 | if (value.indexOf("//") === 0 || value.indexOf("\\\\") === 0) { |
---|
66 | throw "Insupported URL"; |
---|
67 | } |
---|
68 | switch(name){ |
---|
69 | // Note: |
---|
70 | // * dojoUrl is deprecated, and is a synonym for boot |
---|
71 | // * testUrl is deprecated, and is a synonym for test |
---|
72 | // * testModule is deprecated, and is a synonym for test (dots are automatically replaced with slashes) |
---|
73 | // * registerModulePath is deprecated, and is a synonym for paths |
---|
74 | case "boot": |
---|
75 | case "dojoUrl": |
---|
76 | boot= trim(value.split(",")); |
---|
77 | break; |
---|
78 | |
---|
79 | case "test": |
---|
80 | case "testUrl": |
---|
81 | test= trim(value.split(",")); |
---|
82 | break; |
---|
83 | |
---|
84 | case "testModule": |
---|
85 | test= trim(value.replace(/\./g, "/").split(",")); |
---|
86 | break; |
---|
87 | |
---|
88 | // registerModulePath is deprecated; use "paths" |
---|
89 | case "registerModulePath": |
---|
90 | case "paths": |
---|
91 | for(var path, modules = value.split(";"), i= 0; i<modules.length; i++){ |
---|
92 | path= modules[i].split(","); |
---|
93 | paths[trim(path[0])]= trim(path[1]); |
---|
94 | } |
---|
95 | break; |
---|
96 | |
---|
97 | case "breakOnError": |
---|
98 | breakOnError= true; |
---|
99 | break; |
---|
100 | |
---|
101 | case "sandbox": |
---|
102 | sandbox= true; |
---|
103 | break; |
---|
104 | |
---|
105 | case "async": |
---|
106 | async= true; |
---|
107 | break; |
---|
108 | case "dohPlugins": |
---|
109 | dohPlugins=value.split(";"); |
---|
110 | break; |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | var config; |
---|
116 | if(sandbox){ |
---|
117 | // configure the loader assuming the dojo loader; of course the injected boot(s) can override this config |
---|
118 | config= { |
---|
119 | paths: paths, |
---|
120 | // this config uses the dojo loader's scoping features to sandbox the version of dojo used by doh |
---|
121 | packages: [{ |
---|
122 | name: 'doh', |
---|
123 | location: '../util/doh', |
---|
124 | // here's the magic...every time doh asks for a "dojo" module, it gets mapped to a "dohDojo" |
---|
125 | // module; same goes for dojox/dohDojox since doh uses dojox |
---|
126 | packageMap: {dojo:"dohDojo", dojox:"dohDojox"} |
---|
127 | },{ |
---|
128 | // now define the dohDojo package... |
---|
129 | name: 'dohDojo', |
---|
130 | location: '../dojo', |
---|
131 | packageMap: {dojo: "dohDojo", dojox: "dohDojox"} |
---|
132 | },{ |
---|
133 | // and the dohDojox package... |
---|
134 | name: 'dohDojox', |
---|
135 | location: '../dojox', |
---|
136 | // and dojox uses dojo...that is, dohDojox...which must be mapped to dohDojo in the context of dohDojox |
---|
137 | packageMap: {dojo: "dohDojo", dojox: "dohDojox"} |
---|
138 | }], |
---|
139 | |
---|
140 | // next, we need to preposition a special configuration for dohDojo |
---|
141 | cache: { |
---|
142 | "dohDojo*_base/config": function(){ |
---|
143 | define([], { |
---|
144 | // this configuration keeps dojo, dijit, and dojox out of the global space |
---|
145 | scopeMap: [["dojo", "dohDojo"], ["dijit", "dohDijit"], ["dojox", "dohDojox"]], |
---|
146 | isDebug: true, |
---|
147 | noGlobals: true |
---|
148 | }); |
---|
149 | } |
---|
150 | }, |
---|
151 | |
---|
152 | // control the loader; don't boot global dojo, doh will ask for dojo itself |
---|
153 | has: { |
---|
154 | "dojo-sniff": 0, |
---|
155 | "dojo-loader": 1, |
---|
156 | "dojo-boot": 0, |
---|
157 | "dojo-test-sniff": 1 |
---|
158 | }, |
---|
159 | |
---|
160 | // no sniffing; therefore, set the baseUrl |
---|
161 | baseUrl: "../../dojo", |
---|
162 | |
---|
163 | deps: ["dohDojo/domReady", "doh"], |
---|
164 | |
---|
165 | callback: function(domReady, doh){ |
---|
166 | domReady(function(){ |
---|
167 | doh._fixHeight(); |
---|
168 | doh.breakOnError= breakOnError; |
---|
169 | require(test, function(){ |
---|
170 | doh.run(); |
---|
171 | }); |
---|
172 | }); |
---|
173 | }, |
---|
174 | |
---|
175 | async: async |
---|
176 | }; |
---|
177 | }else{ |
---|
178 | config= { |
---|
179 | paths: paths, |
---|
180 | deps: ["dojo/domReady", "doh"], |
---|
181 | callback: function(domReady, doh){ |
---|
182 | domReady(function(){ |
---|
183 | doh._fixHeight(); |
---|
184 | doh.breakOnError= breakOnError; |
---|
185 | require(test, function(){ |
---|
186 | doh.run(); |
---|
187 | }); |
---|
188 | }); |
---|
189 | }, |
---|
190 | async: async, |
---|
191 | isDebug: 1 |
---|
192 | }; |
---|
193 | } |
---|
194 | |
---|
195 | // load all of the dohPlugins |
---|
196 | if(dohPlugins){ |
---|
197 | var i = 0; |
---|
198 | for(i = 0; i < dohPlugins.length; i++){ |
---|
199 | config.deps.push(dohPlugins[i]); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | require = config; |
---|
204 | |
---|
205 | // now script inject any boots |
---|
206 | for(var e, i = 0; i < boot.length; i++) { |
---|
207 | if(boot[i]){ |
---|
208 | e = document.createElement("script"); |
---|
209 | e.type = "text/javascript"; |
---|
210 | e.src = boot[i]; |
---|
211 | e.charset = "utf-8"; |
---|
212 | document.getElementsByTagName("head")[0].appendChild(e); |
---|
213 | } |
---|
214 | } |
---|
215 | })(); |
---|