Skip to content

Commit

Permalink
Patched regex used to load environment-specific config files, and add…
Browse files Browse the repository at this point in the history
…ed tests for env-specific config
  • Loading branch information
sgress454 committed Sep 10, 2015
1 parent 189937d commit 417d772
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ module.exports = function(sails) {
var env = sails.config.environment || async_data['config/local'].environment || 'development';
buildDictionary.aggregate({
dirname : (sails.config.paths.config || sails.config.appPath + '/config') + '/env',
filter : new RegExp(env + ".(" + sails.config.moduleloader.configExt.join('|') + ")$"),
filter : new RegExp("^" + env + "\\.(" + sails.config.moduleloader.configExt.join('|') + ")$"),
optional : true,
flattenDirectories: !(sails.config.dontFlattenConfig),
identity : false
Expand Down
67 changes: 66 additions & 1 deletion test/integration/hook.userconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe('hooks :: ', function() {
async.series([
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/abc.js'), 'module.exports = {"foo":"goo"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/foo/bar.js'), 'module.exports = {"foo":"bar", "abc":123};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/development.js'), 'module.exports = {"cat":"meow"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/development/config.js'), 'module.exports = {"owl":"hoot"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/test-development.js'), 'module.exports = {"duck":"quack"};', cb);},
function(cb) {fs.outputFile(path.resolve(__dirname,'../../testApp/config/env/test-development/config.js'), 'module.exports = {"dog":"woof"};', cb);},
function(cb) {process.chdir('testApp'); cb();}
], done);

Expand Down Expand Up @@ -67,6 +71,67 @@ describe('hooks :: ', function() {

});

});
describe("in development environment", function() {

var sails;
before(function(done) {

Sails().load({hooks:{grunt:false}, dontFlattenConfig: true}, function(err, _sails) {
sails = _sails;
return done(err);
});

});

it("should load config from config/env/development.js", function() {
assert.equal(sails.config.cat, "meow");
});

it("should load config from config/env/development/** files", function() {
assert.equal(sails.config.owl, "hoot");
});

it("should not load config from config/env/test-development/** files", function() {
assert(!sails.config.dog);
});

it("should not load config from config/env/test-development.js", function() {
assert(!sails.config.duck);
});

});

describe("in test-development environment", function() {

var sails;
before(function(done) {

Sails().load({hooks:{grunt:false}, dontFlattenConfig: true, environment: 'test-development'}, function(err, _sails) {
sails = _sails;
return done(err);
});

});

it("should load config from config/env/test-development.js", function() {
assert.equal(sails.config.duck, "quack");
});

it("should load config from config/env/test-development/** files", function() {
assert.equal(sails.config.dog, "woof");
});

it("should not load config from config/env/development/** files", function() {
assert(!sails.config.owl);
});

it("should not load config from config/env/development.js", function() {
assert(!sails.config.cat);
});

});

});


});

0 comments on commit 417d772

Please sign in to comment.