diff --git a/lib/mods.js b/lib/mods.js index 1807d1c..b49b519 100644 --- a/lib/mods.js +++ b/lib/mods.js @@ -44,7 +44,8 @@ module.exports = function getMods(dirpath, opt) { var properties = name.replace('.js', '') .split('/') .map(function(property) { - var reg = /^[a-z][a-z0-9_-]*$/ig; + // want support dao/User.sqlmap.js; + var reg = /^[a-z][a-z\.0-9_-]*$/ig; if (!reg.test(property)) { throw new Error(property + ' is not match ' + reg + ' in ' + name); } diff --git a/test/fixtures/services/dot.dir/a.js b/test/fixtures/services/dot.dir/a.js new file mode 100644 index 0000000..a56b911 --- /dev/null +++ b/test/fixtures/services/dot.dir/a.js @@ -0,0 +1,6 @@ +module.exports = function (app) { + return { + load: true, + app: app + }; +}; diff --git a/test/fixtures/error/dotdir/dot.dir/a.js b/test/fixtures/services/dot.file.js similarity index 100% rename from test/fixtures/error/dotdir/dot.dir/a.js rename to test/fixtures/services/dot.file.js diff --git a/test/loading.test.js b/test/loading.test.js index 3477f82..d705d78 100644 --- a/test/loading.test.js +++ b/test/loading.test.js @@ -27,7 +27,7 @@ describe('loading.test.js', function () { loading(path.join(__dirname, 'fixtures', 'services')).into(app, 'services'); app.should.have.property('services'); - app.services.should.have.keys('dir', 'foo', 'fooBarHello', 'fooService', 'hyphenDir', 'underscoreDir', 'userProfile'); + app.services.should.have.keys('dir', 'foo', 'fooBarHello', 'fooService', 'hyphenDir', 'underscoreDir', 'userProfile', 'dot.dir', 'dot.file'); app.services.fooService.should.have.keys('a'); done = pedding(2, done); diff --git a/test/mods.test.js b/test/mods.test.js index 691add1..0c96513 100644 --- a/test/mods.test.js +++ b/test/mods.test.js @@ -10,7 +10,7 @@ describe('mods.test.js', function() { it('should get mods', function() { var dir = join(fixtures, 'services'); var sortFn = function(x, y){ - return x.fullpath < y.fullpath; + return x.fullpath < y.fullpath ? 1 : -1; }; var mods = getMods(dir).sort(sortFn); mods.should.eql([{ @@ -40,28 +40,35 @@ describe('mods.test.js', function() { }, { fullpath: dir + '/userProfile.js', properties: ['userProfile'] + }, { + fullpath: dir + '/dot.file.js', + properties: ['dot.file'] + }, { + fullpath: dir + '/dot.dir/a.js', + properties: ['dot.dir', 'a'] }].sort(sortFn)); }); - it('should throw when directory contains dot', function() { - (function() { - getMods(join(fixtures, 'error/dotdir')); - }).should.throw('dot.dir is not match /^[a-z][a-z0-9_-]*$/gi in dot.dir/a.js'); - }); + // when support dot file, this case will remove; + // it('should throw when directory contains dot', function() { + // (function() { + // getMods(join(fixtures, 'error/dotdir')); + // }).should.throw('dot.dir is not match /^[a-z][a-z0-9_-]*$/gi in dot.dir/a.js'); + // }); it('should throw when directory starts with underscore', function() { (function() { getMods(join(fixtures, 'error/underscore-dir')); - }).should.throw('_underscore is not match /^[a-z][a-z0-9_-]*$/gi in _underscore/a.js'); + }).should.throw('_underscore is not match /^[a-z][a-z\\.0-9_-]*$/gi in _underscore/a.js'); (function() { getMods(join(fixtures, 'error/underscore-file-in-dir')); - }).should.throw('_a is not match /^[a-z][a-z0-9_-]*$/gi in dir/_a.js'); + }).should.throw('_a is not match /^[a-z][a-z\\.0-9_-]*$/gi in dir/_a.js'); }); it('should throw when file starts with underscore', function() { (function() { getMods(join(fixtures, 'error/underscore-file')); - }).should.throw('_private is not match /^[a-z][a-z0-9_-]*$/gi in _private.js'); + }).should.throw('_private is not match /^[a-z][a-z\\.0-9_-]*$/gi in _private.js'); }); });