added test cases for middleware/component custom dirs
This commit is contained in:
parent
71224d2b0c
commit
bf89a97362
|
@ -1548,9 +1548,7 @@ 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: {
|
||||||
},
|
},
|
||||||
|
@ -1564,21 +1562,7 @@ describe('compiler', function() {
|
||||||
|
|
||||||
appdir.writeConfigFileSync('middleware.json', json);
|
appdir.writeConfigFileSync('middleware.json', json);
|
||||||
|
|
||||||
var instructions;
|
var instructions = boot.compile(appdir.PATH);
|
||||||
|
|
||||||
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'],
|
||||||
|
@ -1606,21 +1590,42 @@ 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 ' +
|
it('supports `middlewareRootDir` option', function() {
|
||||||
'emits middleware instructions for fragment', function() {
|
var middlewareJson = {
|
||||||
testMiddlewareRegistration('loopback#url-not-found',
|
initial: {},
|
||||||
sourceFileForUrlNotFound, true);
|
custom: {
|
||||||
|
'loopback/server/middleware/url-not-found': {
|
||||||
|
params: 'some-config-data',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var customDir = path.resolve(appdir.PATH, 'custom');
|
||||||
|
fs.mkdirsSync(customDir);
|
||||||
|
fs.writeJsonSync(path.resolve(customDir, 'middleware.json'),
|
||||||
|
middlewareJson);
|
||||||
|
|
||||||
|
var instructions = boot.compile({
|
||||||
|
appRootDir: appdir.PATH,
|
||||||
|
middlewareRootDir: path.resolve(appdir.PATH, 'custom'),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(instructions.middleware).to.eql({
|
||||||
|
phases: ['initial', 'custom'],
|
||||||
|
middleware: [
|
||||||
|
{
|
||||||
|
sourceFile: sourceFileForUrlNotFound,
|
||||||
|
config: {
|
||||||
|
phase: 'custom',
|
||||||
|
params: 'some-config-data',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails when a module middleware cannot be resolved', function() {
|
it('fails when a module middleware cannot be resolved', function() {
|
||||||
|
@ -2240,7 +2245,7 @@ describe('compiler', function() {
|
||||||
|
|
||||||
describe('for components', function() {
|
describe('for components', function() {
|
||||||
// Validate merging of component configuration from different locations
|
// Validate merging of component configuration from different locations
|
||||||
function testComponentConfigsMerge(alternativeDirTest) {
|
function testComponentConfigsMerge() {
|
||||||
appdir.createConfigFilesSync();
|
appdir.createConfigFilesSync();
|
||||||
appdir.writeConfigFileSync('component-config.json', {
|
appdir.writeConfigFileSync('component-config.json', {
|
||||||
debug: { option: 'value' },
|
debug: { option: 'value' },
|
||||||
|
@ -2254,31 +2259,7 @@ describe('compiler', function() {
|
||||||
debug: { env: 'applied' },
|
debug: { env: 'applied' },
|
||||||
});
|
});
|
||||||
|
|
||||||
var instructions;
|
var instructions = boot.compile(appdir.PATH);
|
||||||
|
|
||||||
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({
|
||||||
|
@ -2295,9 +2276,28 @@ describe('compiler', function() {
|
||||||
testComponentConfigsMerge();
|
testComponentConfigsMerge();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Suports `componentRootDir` Option And ' +
|
it('supports `componentRootDir` option', function() {
|
||||||
'loads component configs from multiple files', function() {
|
var componentJson = {
|
||||||
testComponentConfigsMerge(true);
|
debug: {
|
||||||
|
option: 'value',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
var customDir = path.resolve(appdir.PATH, 'custom');
|
||||||
|
fs.mkdirsSync(customDir);
|
||||||
|
fs.writeJsonSync(
|
||||||
|
path.resolve(customDir, 'component-config.json'), componentJson);
|
||||||
|
|
||||||
|
var instructions = boot.compile({
|
||||||
|
appRootDir: appdir.PATH,
|
||||||
|
componentRootDir: path.resolve(appdir.PATH, 'custom'),
|
||||||
|
});
|
||||||
|
var component = instructions.components[0];
|
||||||
|
expect(component).to.eql({
|
||||||
|
sourceFile: require.resolve('debug'),
|
||||||
|
config: {
|
||||||
|
option: 'value',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads component relative to appRootDir', function() {
|
it('loads component relative to appRootDir', function() {
|
||||||
|
|
Loading…
Reference in New Issue