knifecycle
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -28,2 +28,4 @@ 'use strict'; | ||
var E_CIRCULAR_DEPENDENCY = 'E_CIRCULAR_DEPENDENCY'; | ||
var E_BAD_SERVICE_PROVIDER = 'E_BAD_SERVICE_PROVIDER'; | ||
var E_BAD_SERVICE_PROMISE = 'E_BAD_SERVICE_PROMISE'; | ||
@@ -335,6 +337,12 @@ // Constants that should use Symbol whenever possible | ||
serviceDescriptorPromise = this._initializeDependencies(siloContext, serviceName, serviceProvider[DEPENDENCIES]).then(function (deps) { | ||
serviceDescriptorPromise = this._initializeDependencies(siloContext, serviceName, serviceProvider[DEPENDENCIES]); | ||
serviceDescriptorPromise = serviceDescriptorPromise.then(function (deps) { | ||
debug('Successfully initialized service dependencies:', serviceName); | ||
return deps; | ||
}).then(serviceProvider).then(function (serviceDescriptor) { | ||
if (!serviceDescriptor) { | ||
debug('Provider did not return a descriptor:', serviceName); | ||
return Promise.reject(new _yerror2.default(E_BAD_SERVICE_PROVIDER, serviceName)); | ||
} | ||
debug('Successfully initialized a service descriptor:', serviceName); | ||
@@ -376,3 +384,6 @@ if (serviceDescriptor.errorPromise) { | ||
siloContext.servicesSequence.push(servicesNames); | ||
return Promise.all(servicesDescriptors.map(function (serviceDescriptor) { | ||
return Promise.all(servicesDescriptors.map(function (serviceDescriptor, index) { | ||
if (!serviceDescriptor.servicePromise || !serviceDescriptor.servicePromise.then) { | ||
return Promise.reject(new _yerror2.default(E_BAD_SERVICE_PROMISE, servicesNames[index])); | ||
} | ||
return serviceDescriptor.servicePromise.then(function (service) { | ||
@@ -379,0 +390,0 @@ return service; |
@@ -182,2 +182,37 @@ 'use strict'; | ||
it('should fail with bad service', function (done) { | ||
$.service('lol', function () {}); | ||
$.run(['lol']).then(function () { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}).catch(function (err) { | ||
_assert2.default.deepEqual(err.code, 'E_BAD_SERVICE_PROMISE'); | ||
_assert2.default.deepEqual(err.params, ['lol']); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should fail with bad provider', function (done) { | ||
$.provider('lol', function () {}); | ||
$.run(['lol']).then(function () { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}).catch(function (err) { | ||
_assert2.default.deepEqual(err.code, 'E_BAD_SERVICE_PROVIDER'); | ||
_assert2.default.deepEqual(err.params, ['lol']); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should fail with bad service in a provider', function (done) { | ||
$.provider('lol', function () { | ||
return Promise.resolve({}); | ||
}); | ||
$.run(['lol']).then(function () { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}).catch(function (err) { | ||
_assert2.default.deepEqual(err.code, 'E_BAD_SERVICE_PROMISE'); | ||
_assert2.default.deepEqual(err.params, ['lol']); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should fail with undeclared dependencies', function (done) { | ||
@@ -184,0 +219,0 @@ $.run(['lol']).then(function () { |
{ | ||
"name": "knifecycle", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Manage your NodeJS processes's lifecycle.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,2 +10,4 @@ import YError from 'yerror'; | ||
const E_CIRCULAR_DEPENDENCY = 'E_CIRCULAR_DEPENDENCY'; | ||
const E_BAD_SERVICE_PROVIDER = 'E_BAD_SERVICE_PROVIDER'; | ||
const E_BAD_SERVICE_PROMISE = 'E_BAD_SERVICE_PROMISE'; | ||
@@ -310,3 +312,5 @@ // Constants that should use Symbol whenever possible | ||
serviceProvider[DEPENDENCIES] | ||
) | ||
); | ||
serviceDescriptorPromise = serviceDescriptorPromise | ||
.then((deps) => { | ||
@@ -318,2 +322,6 @@ debug('Successfully initialized service dependencies:', serviceName); | ||
.then((serviceDescriptor) => { | ||
if((!serviceDescriptor)) { | ||
debug('Provider did not return a descriptor:', serviceName); | ||
return Promise.reject(new YError(E_BAD_SERVICE_PROVIDER, serviceName)); | ||
} | ||
debug('Successfully initialized a service descriptor:', serviceName); | ||
@@ -359,3 +367,8 @@ if(serviceDescriptor.errorPromise) { | ||
return Promise.all(servicesDescriptors.map( | ||
serviceDescriptor => serviceDescriptor.servicePromise.then(service => service) | ||
(serviceDescriptor, index) => { | ||
if((!serviceDescriptor.servicePromise) || !serviceDescriptor.servicePromise.then) { | ||
return Promise.reject(new YError(E_BAD_SERVICE_PROMISE, servicesNames[index])); | ||
} | ||
return serviceDescriptor.servicePromise.then(service => service); | ||
} | ||
)); | ||
@@ -362,0 +375,0 @@ }) |
@@ -184,2 +184,44 @@ import assert from 'assert'; | ||
it('should fail with bad service', (done) => { | ||
$.service('lol', () => {}); | ||
$.run(['lol']) | ||
.then(() => { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}) | ||
.catch((err) => { | ||
assert.deepEqual(err.code, 'E_BAD_SERVICE_PROMISE'); | ||
assert.deepEqual(err.params, ['lol']); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
it('should fail with bad provider', (done) => { | ||
$.provider('lol', () => {}); | ||
$.run(['lol']) | ||
.then(() => { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}) | ||
.catch((err) => { | ||
assert.deepEqual(err.code, 'E_BAD_SERVICE_PROVIDER'); | ||
assert.deepEqual(err.params, ['lol']); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
it('should fail with bad service in a provider', (done) => { | ||
$.provider('lol', () => Promise.resolve({})); | ||
$.run(['lol']) | ||
.then(() => { | ||
done(new Error('E_UNEXPECTED_SUCCESS')); | ||
}) | ||
.catch((err) => { | ||
assert.deepEqual(err.code, 'E_BAD_SERVICE_PROMISE'); | ||
assert.deepEqual(err.params, ['lol']); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
it('should fail with undeclared dependencies', (done) => { | ||
@@ -186,0 +228,0 @@ $.run(['lol']) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69386
1340