Ignore models/ and boot/ subdirs without index

Sub-directories of `models/` and `boot/` that cannot be required
(they don't have an index.js file) are silently skipped now.

This enables developers to put test files into `models/test/`.
This commit is contained in:
Miroslav Bajtoš 2014-05-27 16:44:21 +02:00
parent a716cdbf7b
commit 255217f6a7
3 changed files with 18 additions and 1 deletions

View File

@ -4,6 +4,7 @@ var path = require('path');
var _ = require('underscore');
var loopback = require('loopback');
var ConfigLoader = require('./lib/config-loader');
var debug = require('debug')('loopback-boot');
/**
* Initialize an application from an options object or
@ -287,6 +288,10 @@ function tryRequire(modulePath) {
try {
return require.apply(this, arguments);
} catch(e) {
if(e.code === 'MODULE_NOT_FOUND') {
debug('Warning: cannot require %s - module not found.', modulePath);
return undefined;
}
console.error('failed to require "%s"', modulePath);
throw e;
}

View File

@ -22,7 +22,8 @@
"url": "https://github.com/strongloop/loopback-boot/blob/master/LICENSE"
},
"dependencies": {
"underscore": "^1.6.0"
"underscore": "^1.6.0",
"debug": "^0.8.1"
},
"devDependencies": {
"loopback": "^1.5.0",

View File

@ -379,6 +379,17 @@ describe('bootLoopBackApp', function() {
boot(app, appDir);
expect(global.fnCalled, 'exported fn was called').to.be.undefined();
});
it('supports models/ subdirectires that are not require()able', function() {
givenAppInSandbox();
writeAppFile('models/test/model.test.js',
'throw new Error("should not been called");');
var app = loopback();
boot(app, appDir);
// no assert, the test passed when we got here
});
});
});