245 lines
6.0 KiB
JavaScript
245 lines
6.0 KiB
JavaScript
/*
|
|
* 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
|
|
*/
|