I have an init file that provides a function that bootstraps RequireJS via require.config()
. The configuration ends up looking something (mostly) like this:
...
config =
baseUrl: sysDir + 'lib/'
paths:
app: appDir + 'lib/'
dep: sysDir + 'vendor/'
deps: [
'dep/underscore/underscore.min'
'dep/jquery/jquery.min'
]
require.config config
This file is used in the browser and I want to use it in node too. I was trying to do the same thing in a helper but I'm not having much luck. Due to the way specs are ran in a new VM context, I'm not really sure what to do and there's no obvious way to pass jasmine-node your RequireJS config.
Any ideas?
I got this to kinda work by putting the require config into a spec_helper.js at the root of my specs directory:
define = require('requirejs');
(function () {
var baseUrl = __dirname + '/../smoke'
console.log('Configuring requirejs with baseurl: ' + baseUrl)
define.config({
'nodeRequire': global.require,
'baseUrl': baseUrl
});
})();
Not sure if that will really solve your problem or not.
jasmine-node provides a sample project for requirejs: https://github.com/mhevery/jasmine-node#requirejs
if you call your tests like > jasmine-node --runWithRequireJs --requireJsSetup tests/requirejs-setup.js tests
, you can add your configuration settings in the requirejs-setup - file.
nevertheless i've had a problem with the baseUrl-setting. in the requirejs-wrapper-template.js the baseUrl is manipulated and set relative to the current executed test file, which you can see here:
if(alteredConfig.baseUrl){
var base = baseUrl.replace(/\\/g, '/'),
splitUrl = alteredConfig.baseUrl.replace(/\\/g, '/').split('/'),
index = 0;
for(; index < splitUrl.length; index++){
if(splitUrl[index] === '..') {
base = path.dirname(base);
} else {
base += '/' + splitUrl[index];
}
}
alteredConfig.baseUrl = base;
}
this leads to problems with defined paths from my requirejs config. so i simply commented out this code block. and now it works very well for me.