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:
parent
a716cdbf7b
commit
255217f6a7
5
index.js
5
index.js
|
@ -4,6 +4,7 @@ var path = require('path');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var loopback = require('loopback');
|
var loopback = require('loopback');
|
||||||
var ConfigLoader = require('./lib/config-loader');
|
var ConfigLoader = require('./lib/config-loader');
|
||||||
|
var debug = require('debug')('loopback-boot');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize an application from an options object or
|
* Initialize an application from an options object or
|
||||||
|
@ -287,6 +288,10 @@ function tryRequire(modulePath) {
|
||||||
try {
|
try {
|
||||||
return require.apply(this, arguments);
|
return require.apply(this, arguments);
|
||||||
} catch(e) {
|
} 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);
|
console.error('failed to require "%s"', modulePath);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,8 @@
|
||||||
"url": "https://github.com/strongloop/loopback-boot/blob/master/LICENSE"
|
"url": "https://github.com/strongloop/loopback-boot/blob/master/LICENSE"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"underscore": "^1.6.0"
|
"underscore": "^1.6.0",
|
||||||
|
"debug": "^0.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"loopback": "^1.5.0",
|
"loopback": "^1.5.0",
|
||||||
|
|
|
@ -379,6 +379,17 @@ describe('bootLoopBackApp', function() {
|
||||||
boot(app, appDir);
|
boot(app, appDir);
|
||||||
expect(global.fnCalled, 'exported fn was called').to.be.undefined();
|
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
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue