Updated Using dojo and dojo class loading in jasmine headless webkit (markdown)

kidlingo 2011-07-26 07:40:46 -07:00
parent 40fcb44e77
commit 1596fd4748

@ -25,16 +25,26 @@ jasmine-headless-webkit --jasmine-config ./jasmine.yml
## The problems this solves:
- Dojo classes call dojo.require and dojo,declare, so dojo needs to be a global variable by the time those files are loaded and parsed. Including dojo.js before the general glob pattern seems to ensure that dojo.js is loaded and run before anything after it. Likewise for jQuery.
### Creating the global dojo object
- The second issue then is telling dojo where to find class files (modules), so if I have this in a js file:
Dojo classes call dojo.require and dojo,declare, so dojo needs to be a global variable by the time those files are loaded and parsed. Including dojo.js before the general glob pattern seems to ensure that dojo.js is loaded and run before anything after it. Likewise for jQuery.
### Loading dojo classes using file URLs, i.e. not requiring a server
The second issue then is telling dojo where to find class files (modules), and getting it to load them using file URLs instead of http URLs, so if I have this in a js file:
dojo.require("mystuff.SomethingCool");
dojo knows where to look for mystuff/SomethingCool.js in the load path. You do this by creating a global djConfig object before loading dojo.js, providing two key pieces of information. One is modulePaths, which is how you tell dojo where to find things. The other is baseScriptUri, which tells dojo where its home is. baseScriptUri lets you specify the URL as a file URL, and dojo will load class files using file URLs instead of requiring a server.
dojo knows where to look for mystuff/SomethingCool.js in the load path.
To create this global djConfig object, I include the test_bootstrap.js in the src_files list before dojo.js, which seems to ensure that test_bootstrap.js is run before dojo.js, thereby configuring dojo correctly.
You do this by creating a global djConfig object before loading dojo.js, providing two key pieces of information. One is modulePaths, which is how you tell dojo where to find things. The other is baseScriptUri, which tells dojo where its home is.
- The third issue is getting dojo to stop trying to load firebug.js. You do this by setting isDebug to false.
Unlike djConfig.baseUrl, djConfig.baseScriptUri lets you specify the URL as a file URL, and dojo will load class files using file URLs instead of requiring a server.
To create this global djConfig object, I include the test_bootstrap.js in the src_files list before dojo.js, which seems to ensure that test_bootstrap.js is run before dojo.js, thereby configuring dojo correctly when it loads.
### Stop trying to load firebug.js
The third issue is getting dojo to stop trying to load firebug.js. You do this by setting isDebug to false.
And away you go. You can call dojo.require() in your specs and create instances of dojo classes for testing.