app.boot() now loads the "boot" directory

This commit is contained in:
Ritchie Martori 2013-12-17 19:15:48 -08:00
parent 16b790a93a
commit 981bdd4c81
6 changed files with 26 additions and 1 deletions

View File

@ -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**

View File

@ -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) {

View File

@ -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);

1
test/fixtures/simple-app/boot/bad.txt vendored Normal file
View File

@ -0,0 +1 @@
this is not a js file!

1
test/fixtures/simple-app/boot/foo.js vendored Normal file
View File

@ -0,0 +1 @@
process.loadedFooJS = true;

View File

@ -0,0 +1 @@
process.loadedBarJS = true;