forked from mhevery/jasmine-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run each requirejs spec in it's own context so global variables don't…
… accidentally polute over to multiple spec files.
- Loading branch information
Showing
5 changed files
with
181 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var test = function(require, define, undefined) { #REPLACE TEST SCRIPT# | ||
}; | ||
|
||
var requirejsOrig = require('requirejs'), | ||
ostring = Object.prototype.toString, | ||
path = require('path'), | ||
baseUrl = '#REPLACE URL#', | ||
isArray = function(it){ | ||
return ostring.call(it) === '[object Array]'; | ||
}, | ||
isFunction = function(it){ | ||
return ostring.call(it) === '[object Function]'; | ||
}, | ||
requirejs = function(deps, callback){ | ||
var retVal; | ||
|
||
if(!isArray(deps) && typeof deps !== 'string'){ | ||
if(isArray(callback)){ | ||
retVal = requirejsOrig(deps, callback, arguments[2]); | ||
} else { | ||
retVal = requirejsOrig(deps, [], callback); | ||
} | ||
} else { | ||
retVal = requirejsOrig(deps, callback); | ||
} | ||
|
||
return retVal; | ||
}; | ||
|
||
requirejsOrig.config({ | ||
baseUrl: baseUrl, | ||
nodeRequire: require | ||
}); | ||
|
||
for(var key in requirejsOrig) { | ||
requirejs[key] = requirejsOrig[key]; | ||
} | ||
|
||
requirejs.config = function(config){ | ||
var alteredConfig = {}; | ||
|
||
for(var key in config) { | ||
alteredConfig[key] = config[key]; | ||
} | ||
|
||
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; | ||
} | ||
|
||
return requirejsOrig.config(alteredConfig); | ||
}; | ||
|
||
test(requirejs, requirejs.define); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters