added test cases to validate the middlewares & components configuration custom directory support

This commit is contained in:
Doped Dude 2016-02-10 04:46:37 +05:30
parent dba37ba744
commit 9767a823b6
1 changed files with 67 additions and 6 deletions

View File

@ -1546,7 +1546,8 @@ describe('compiler', function() {
describe('for middleware', function() { describe('for middleware', function() {
function testMiddlewareRegistration(middlewareId, sourceFile) { function testMiddlewareRegistration(middlewareId, sourceFile,
alternativeDirTest) {
var json = { var json = {
initial: { initial: {
}, },
@ -1560,7 +1561,21 @@ describe('compiler', function() {
appdir.writeConfigFileSync('middleware.json', json); appdir.writeConfigFileSync('middleware.json', json);
var instructions = boot.compile(appdir.PATH); var instructions;
if (alternativeDirTest === true) {
var customDir = path.resolve(appdir.PATH, 'custom');
fs.mkdirsSync(customDir);
fs.renameSync(
path.resolve(appdir.PATH, 'middleware.json'),
path.resolve(customDir, 'middleware.json'));
instructions = boot.compile({
appRootDir: appdir.PATH,
middlewareRootDir: path.resolve(appdir.PATH, 'custom')
});
} else {
instructions = boot.compile(appdir.PATH);
}
expect(instructions.middleware).to.eql({ expect(instructions.middleware).to.eql({
phases: ['initial', 'custom'], phases: ['initial', 'custom'],
@ -1588,11 +1603,23 @@ describe('compiler', function() {
sourceFileForUrlNotFound); sourceFileForUrlNotFound);
}); });
it('Suports `middlewareRootDir` Option And ' +
'emits middleware instructions', function() {
testMiddlewareRegistration('loopback/server/middleware/url-not-found',
sourceFileForUrlNotFound, true);
});
it('emits middleware instructions for fragment', function() { it('emits middleware instructions for fragment', function() {
testMiddlewareRegistration('loopback#url-not-found', testMiddlewareRegistration('loopback#url-not-found',
sourceFileForUrlNotFound); sourceFileForUrlNotFound);
}); });
it('Suports `middlewareRootDir` Option And ' +
'emits middleware instructions for fragment', function() {
testMiddlewareRegistration('loopback#url-not-found',
sourceFileForUrlNotFound, true);
});
it('fails when a module middleware cannot be resolved', function() { it('fails when a module middleware cannot be resolved', function() {
appdir.writeConfigFileSync('middleware.json', { appdir.writeConfigFileSync('middleware.json', {
final: { final: {
@ -2209,7 +2236,8 @@ describe('compiler', function() {
}); });
describe('for components', function() { describe('for components', function() {
it('loads component configs from multiple files', function() { // Validate merging of component configuration from different locations
function testComponentConfigsMerge(alternativeDirTest) {
appdir.createConfigFilesSync(); appdir.createConfigFilesSync();
appdir.writeConfigFileSync('component-config.json', { appdir.writeConfigFileSync('component-config.json', {
debug: { option: 'value' } debug: { option: 'value' }
@ -2223,7 +2251,31 @@ describe('compiler', function() {
debug: {env: 'applied'} debug: {env: 'applied'}
}); });
var instructions = boot.compile(appdir.PATH); var instructions;
if (alternativeDirTest === true) {
var customDir = path.resolve(appdir.PATH, 'custom');
fs.mkdirsSync(customDir);
fs.renameSync(
path.resolve(appdir.PATH, 'component-config.json'),
path.resolve(customDir, 'component-config.json'));
fs.renameSync(
path.resolve(appdir.PATH, 'component-config.local.json'),
path.resolve(customDir, 'component-config.local.json'));
fs.renameSync(
path.resolve(appdir.PATH, 'component-config.' + env + '.json'),
path.resolve(customDir, 'component-config.' + env + '.json'));
instructions = boot.compile({
appRootDir: appdir.PATH,
componentRootDir: path.resolve(appdir.PATH, 'custom')
});
} else {
instructions = boot.compile(appdir.PATH);
}
var component = instructions.components[0]; var component = instructions.components[0];
expect(component).to.eql({ expect(component).to.eql({
@ -2234,6 +2286,15 @@ describe('compiler', function() {
env: 'applied' env: 'applied'
} }
}); });
}
it('loads component configs from multiple files', function() {
testComponentConfigsMerge();
});
it('Suports `componentRootDir` Option And ' +
'loads component configs from multiple files', function() {
testComponentConfigsMerge(true);
}); });
it('loads component relative to appRootDir', function() { it('loads component relative to appRootDir', function() {