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

@ -2,39 +2,49 @@ I love this gem - thanks for the great work. My project uses a mix of dojo and
## jasmine.yml:
src_files:
- WebContent/js/test_bootstrap.js
- WebContent/js/lib/dojo/dojo.js
- WebContent/js/lib/jquery/jquery-1.4.4.js
- WebContent/js/lib/mystuff/**/*.js
spec_files:
- "WebContent/js/lib/mystuff/**/*[Ss]pec.js"
src_files:
- WebContent/js/test_bootstrap.js
- WebContent/js/lib/dojo/dojo.js
- WebContent/js/lib/jquery/jquery-1.4.4.js
- WebContent/js/lib/mystuff/**/*.js
spec_files:
- "WebContent/js/lib/mystuff/**/*[Ss]pec.js"
## WebContent/js/test_bootstrap.js:
djConfig = {
baseScriptUri: "file:///Users/me/projects/myproject/WebContent/js/lib/dojo",
modulePaths: {'mystuff': 'file:///Users/me/projects/myproject/WebContent/js/lib/mystuff'},
isDebug:false,
parseOnLoad: true
};
djConfig = {
baseScriptUri: "file:///Users/me/projects/myproject/WebContent/js/lib/dojo",
modulePaths: {'mystuff': 'file:///Users/me/projects/myproject/WebContent/js/lib/mystuff'},
isDebug:false,
parseOnLoad: true
};
## the command line:
jasmine-headless-webkit --jasmine-config ./jasmine.yml
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.
dojo.require("mystuff.SomethingCool");
### Loading dojo classes using file URLs, i.e. not requiring a server
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.
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:
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.
dojo.require("mystuff.SomethingCool");
- The third issue is getting dojo to stop trying to load firebug.js. You do this by setting isDebug to false.
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.
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.