This commit is contained in:
MishaBagger
2023-10-25 09:15:21 +03:00
commit b6c10cc93f
9828 changed files with 1446743 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
/** Custom RequireJS setup file to test user-specified setup files */
/* We want to minimize behavior changes between this test setup file and the
* default setup file to avoid breaking tests which rely on any (current or
* future) default behavior. So we:
* - Run the normal setup file
* - Avoid introducing additional global variables
* - Avoid maintaining two copies of the setup file
*/
eval(require('fs').readFileSync(baseUrl + '../lib/jasmine-node/requirejs-wrapper-template.js', 'utf8'));
// This is our indicator that this custom setup script has run
var setupHasRun = true;

View File

@@ -0,0 +1,78 @@
/* Setup file run before spec files to setup the context (and RequireJS
* specifically) to execute the spec file.
*
* Defined by caller:
* - Jasmine predefines
* - require (Node require)
* - __dirname, __filename
* - baseUrl (Relative path to the directory containing this file)
* - csPath (Path to require-cs module)
*
* See requirejs-runner source for full invocation details.
*/
var define,
requirejsOrig = require('requirejs'),
ostring = Object.prototype.toString,
path = require('path'),
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,
paths: {
cs: csPath
}
});
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);
};
require = requirejs;
define = requirejs.define;

View File

@@ -0,0 +1,19 @@
require(['requirejs.sut'], function(sut){
describe('RequireJs basic tests', function(){
beforeEach(function(){
expect(true).toBeTruthy();
});
afterEach(function(){
expect(true).toBeTruthy();
});
it('should load sut', function(){
expect(sut.name).toBe('Subject To Test');
expect(sut.method(2)).toBe(3);
});
it('should run setup', function(){
expect(typeof setupHasRun).toBe('boolean');
});
});
});

View File

@@ -0,0 +1,8 @@
define(function(){
return {
name: 'Subject To Test',
method: function(input){
return 1+input;
}
};
});