app.boot() now loads the "boot" directory
This commit is contained in:
parent
16b790a93a
commit
981bdd4c81
|
@ -58,6 +58,7 @@ Initialize an application from an options object or a set of JSON and JavaScript
|
|||
1. **DataSources** are created from an `options.dataSources` object or `datasources.json` in the current directory
|
||||
2. **Models** are created from an `options.models` object or `models.json` in the current directory
|
||||
3. Any JavaScript files in the `./models` directory are loaded with `require()`.
|
||||
4. Any JavaScript files in the `./boot` directory are loaded with `require()`.
|
||||
|
||||
**Options**
|
||||
|
||||
|
|
|
@ -290,6 +290,7 @@ app.boot = function(options) {
|
|||
|
||||
// require directories
|
||||
var requiredModels = requireDir(path.join(appRootDir, 'models'));
|
||||
var requiredBootScripts = requireDir(path.join(appRootDir, 'boot'));
|
||||
}
|
||||
|
||||
function assertIsValidConfig(name, config) {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
var path = require('path');
|
||||
var SIMPLE_APP = path.join(__dirname, 'fixtures', 'simple-app');
|
||||
|
||||
describe('app', function() {
|
||||
|
||||
describe('app.model(Model)', function() {
|
||||
|
@ -75,6 +78,23 @@ describe('app', function() {
|
|||
expect(this.app.get('baz')).to.eql(true);
|
||||
});
|
||||
|
||||
describe('boot and models directories', function() {
|
||||
beforeEach(function() {
|
||||
var app = this.app = loopback();
|
||||
app.boot(SIMPLE_APP);
|
||||
});
|
||||
|
||||
it('should run all modules in the boot directory', function () {
|
||||
assert(process.loadedFooJS);
|
||||
delete process.loadedFooJS;
|
||||
});
|
||||
|
||||
it('should run all modules in the models directory', function () {
|
||||
assert(process.loadedBarJS);
|
||||
delete process.loadedBarJS;
|
||||
});
|
||||
});
|
||||
|
||||
describe('PaaS and npm env variables', function() {
|
||||
beforeEach(function() {
|
||||
this.boot = function () {
|
||||
|
@ -162,7 +182,7 @@ describe('app', function() {
|
|||
it('Load config files', function () {
|
||||
var app = loopback();
|
||||
|
||||
app.boot(require('path').join(__dirname, 'fixtures', 'simple-app'));
|
||||
app.boot(SIMPLE_APP);
|
||||
|
||||
assert(app.models.foo);
|
||||
assert(app.models.Foo);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
this is not a js file!
|
|
@ -0,0 +1 @@
|
|||
process.loadedFooJS = true;
|
|
@ -0,0 +1 @@
|
|||
process.loadedBarJS = true;
|
Loading…
Reference in New Issue