Initial commit
This commit is contained in:
4
test/autoload/test.autoload.js
Normal file
4
test/autoload/test.autoload.js
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
module.exports = function() {
|
||||
throw new Error('autoloaded');
|
||||
};
|
||||
9
test/constructor/nested/four.js
Normal file
9
test/constructor/nested/four.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/constructor/nested/last/five.js
Normal file
9
test/constructor/nested/last/five.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 5;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/constructor/one.js
Normal file
9
test/constructor/one.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/constructor/two.js
Normal file
9
test/constructor/two.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/loading/module.js
Normal file
9
test/loading/module.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run: function () {
|
||||
return modular('module2').run();
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/loading/module2.js
Normal file
9
test/loading/module2.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
run : function () {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/loading/module3.js
Normal file
9
test/loading/module3.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run: function () {
|
||||
return modular('nested.module4').run();
|
||||
}
|
||||
};
|
||||
};
|
||||
11
test/loading/module5.js
Normal file
11
test/loading/module5.js
Normal file
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var mod;
|
||||
|
||||
module.exports.onLoad = function (modular) {
|
||||
mod = modular('module6');
|
||||
};
|
||||
|
||||
module.exports.run = function () {
|
||||
return mod.run();
|
||||
};
|
||||
9
test/loading/module6.js
Normal file
9
test/loading/module6.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
run : function () {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/loading/nested/module4.js
Normal file
9
test/loading/nested/module4.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function() {
|
||||
return {
|
||||
run : function () {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/override/constructor/one.js
Normal file
9
test/override/constructor/one.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 3;
|
||||
}
|
||||
};
|
||||
};
|
||||
9
test/override/constructor/two.js
Normal file
9
test/override/constructor/two.js
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (modular) {
|
||||
return {
|
||||
run : function () {
|
||||
return 4;
|
||||
}
|
||||
};
|
||||
};
|
||||
244
test/test.js
Normal file
244
test/test.js
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Unit tests for modular
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var modular = require('../lib/modular.js');
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
//Load a file without any options
|
||||
describe('Modular', function() {
|
||||
describe('Settings', function() {
|
||||
it('load a single module', function() {
|
||||
modular({
|
||||
files : './constructor/one.js',
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a single module with settings', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor/one.js',
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load two modules', function() {
|
||||
modular({
|
||||
files : [ './constructor/one.js', './constructor/two.js' ],
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
assert.equal (2, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load two modules with settings', function() {
|
||||
modular({
|
||||
files : [ {
|
||||
path: './constructor/one.js'
|
||||
}, {
|
||||
path: './constructor/two.js'
|
||||
}],
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
assert.equal (2, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a directory', function() {
|
||||
modular({
|
||||
files : './constructor',
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
assert.equal (2, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a directory with settings', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor'
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
assert.equal (2, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a single module with namespace and name', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor/one.js',
|
||||
namespace: 'namespace',
|
||||
name: 'class'
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('namespace.class').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a directories with override', function() {
|
||||
modular({
|
||||
files : ['./constructor', {
|
||||
path: './override',
|
||||
basePath: './override',
|
||||
override: true
|
||||
}
|
||||
]
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (3, modular('constructor.one').run());
|
||||
assert.equal (4, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load a directories with no override', function() {
|
||||
modular({
|
||||
files : ['./constructor', {
|
||||
path: './override',
|
||||
override: false
|
||||
}
|
||||
]
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('constructor.one').run());
|
||||
assert.equal (2, modular('constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load nested directories', function() {
|
||||
modular({
|
||||
files : './constructor'
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (4, modular('constructor.nested.four').run());
|
||||
assert.equal (5, modular('constructor.nested.last.five').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load directory with global base path', function() {
|
||||
modular({
|
||||
files : './constructor',
|
||||
basePath : './constructor'
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('one').run());
|
||||
assert.equal (2, modular('two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load directory with per directory base path', function() {
|
||||
modular({
|
||||
files : [{
|
||||
path: './constructor',
|
||||
basePath : './constructor'
|
||||
},{
|
||||
path: './override'
|
||||
}]
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('one').run());
|
||||
assert.equal (2, modular('two').run());
|
||||
assert.equal (3, modular('override.constructor.one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load file with global base path', function() {
|
||||
modular({
|
||||
files : './constructor/one.js',
|
||||
basePath : './constructor'
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load file with per file base path', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor/one.js',
|
||||
basePath : './constructor'
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load file with base namespace', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor/one.js',
|
||||
baseNamespace: 'namespace'
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('namespace.constructor.one').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load directory with base namespace', function() {
|
||||
modular({
|
||||
files : {
|
||||
path: './constructor',
|
||||
baseNamespace: 'namespace'
|
||||
}
|
||||
}).on('start', function(modular) {
|
||||
assert.equal (1, modular('namespace.constructor.one').run());
|
||||
assert.equal (2, modular('namespace.constructor.two').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('autoload modules', function() {
|
||||
assert.throws(function(){
|
||||
modular({
|
||||
files : {
|
||||
path: './autoload',
|
||||
}
|
||||
}).start();
|
||||
},
|
||||
/autoloaded/);
|
||||
});
|
||||
|
||||
it('exclude module', function() {
|
||||
assert.throws(function(){
|
||||
modular({
|
||||
files : './constructor',
|
||||
exclude: ['./constructor/two.js']
|
||||
}).on('start', function(modular) {
|
||||
modular('two').run();
|
||||
}).start();
|
||||
},
|
||||
/Unresolved dependency two/);
|
||||
});
|
||||
});
|
||||
|
||||
describe ('Modules', function() {
|
||||
it('load modules in the same namespace', function() {
|
||||
modular({
|
||||
files: './loading'
|
||||
}).on('start', function (modular) {
|
||||
assert.equal (1, modular('loading.module').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('load modules in sub namespace', function() {
|
||||
modular({
|
||||
files: './loading'
|
||||
}).on('start', function (modular) {
|
||||
assert.equal (1, modular('loading.module3').run());
|
||||
}).start();
|
||||
});
|
||||
|
||||
it('access modules through onLoad function', function() {
|
||||
modular({
|
||||
files: ['./loading/module5.js',
|
||||
'./loading/module6.js' ]
|
||||
}).on('start', function (modular) {
|
||||
assert.equal (1, modular('loading.module5').run());
|
||||
}).start();
|
||||
});
|
||||
});
|
||||
});
|
||||
/* A tester
|
||||
* Live reload
|
||||
* Autorestart
|
||||
* Log
|
||||
*/
|
||||
Reference in New Issue
Block a user