I've been trying to use requirejs and js-test-driver along side, and I can't seen to get it working.
I have a minimal configuration like this at the root :
server: http://localhost:9876
load:
- src/main/resources/web/resources/vendor/requirejs/require.js
test:
- src/test/js/*.js
A "src/main/js/greeter.js" file defines a silly module :
define(function(require) {
myapp = {};
myapp.Greeter = function() {
};
myapp.Greeter.prototype.greet = function(name) {
return "Hello " + name + "!";
};
return myapp;
});
And I'm trying to let require load the greeter module in a "src/test/js/greeterTest.js" :
GreeterTest = TestCase("GreeterTest");
require.configure({ ???? });
require([ "src/main/js/greeter" ], function(myapp) {
GreeterTest.prototype.testGreet = function() {
var greeter = new myapp.Greeter();
assertEquals("Hello World!", greeter.greet("World"));
};
});
Whenever I run this, I get an error because myapp is not defined when creating the Greeter.
So is there a way I can configure require in this case ? I tried :
- setting the baseUrl property to something like file:///.... to give the location of the file
- using the gateway configuration to proxy the requests that requirejs might do (although I have no server running to serve the js files, so again I had to use file:///)
Is there something else I should try ?
Thanks
Turns out it is possible, but poorly documented :
So this works :
And requirejs has to be configured like this :
Notice :