Skip to content

Commit

Permalink
Fixed an error that was causing the acqua to print 'dependency not fo…
Browse files Browse the repository at this point in the history
…und' on a existant module dependency
  • Loading branch information
sergiofilhowz committed Jul 1, 2015
1 parent e487640 commit 7d5b4f8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ First Release of Acqua

var acqua = new Acqua({
dependencies : [ anotherAcqua ]
});
});

# Version 0.0.5

**[HOTFIX]** Fixed an error that was causing the acqua to print 'dependency not found' on a existant module dependency
13 changes: 7 additions & 6 deletions lib/acqua.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ var fs = require('fs'),
_ = require('lodash'),
path = require('path');

function DependencyError(message) {
function DependencyError(message, modules) {
this.name = 'DependencyError';
this.message = message;
this.modules = modules;
this.stack = new Error(message).stack;
}
DependencyError.prototype = Error.prototype;
Expand Down Expand Up @@ -116,7 +117,7 @@ Acqua.prototype.exec = function (fn) {

Acqua.prototype.execModule = function ($module, modulePath) {

var dependencies = this.getDependencies($module);
var dependencies = this.getDependencies($module, modulePath);
if (_.isString(modulePath)) {
this.log('Importing module: ' + modulePath);
}
Expand Down Expand Up @@ -163,8 +164,8 @@ Acqua.prototype.loadDir = function (dir, importFunction) {
});

if (newPendentModules.length === pendentModules.length && newPendentModules.length > 0) {
throw new Error('Dependency Error on the Following Modules: (Might be a circular dependency) '
+ JSON.stringify(pendentModules, null, 4));
throw new DependencyError('Dependency Error on the Following Modules: (Might be a circular dependency) '
+ JSON.stringify(newPendentModules, null, 4), newPendentModules);
}
pendentModules = newPendentModules;

Expand Down Expand Up @@ -197,7 +198,7 @@ Acqua.prototype.internalLoadFile = function (dir, file, importFunction, pendentM
this.importModule(location);
} catch (err) {
if (err instanceof DependencyError && pendentModules !== undefined) {
pendentModules.push({directory: dir, file: file, error: err.message});
pendentModules.push({ directory: dir, file: file, error: err.message });
} else {
throw err;
}
Expand Down Expand Up @@ -229,4 +230,4 @@ Acqua.prototype.namespace = function (name) {
return this.namespaces[name];
};

module.exports = Acqua;
module.exports = Acqua;
19 changes: 18 additions & 1 deletion test/acqua.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Acqua', function () {
it('should import modules in any order', function () {

var acqua = new Acqua();
acqua.loadDir(path.join(__dirname, 'mocks'));
acqua.loadDir(path.join(__dirname, 'mocks/test1'));

var one = acqua.get('one'),
two = acqua.get('two');
Expand All @@ -102,6 +102,23 @@ describe('Acqua', function () {

});

it('should import modules in any order, and show correct error', function () {

var acqua = new Acqua(),
error = false;

try {
acqua.loadDir(path.join(__dirname, 'mocks/test2'));
} catch (err) {
error = true;
expect(err.modules).with.length(1);
expect(err.modules[0]).to.have.property('error').be.equal('Dependency module does not exist: three');
}

expect(error).to.be.true;

});

it('should handle context dependencies', function () {

var acqua = new Acqua();
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions test/mocks/test2/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function one(two, three) {

this.two = two;
this.three = three;

return this;
};
3 changes: 3 additions & 0 deletions test/mocks/test2/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function two() {
return this;
};

0 comments on commit 7d5b4f8

Please sign in to comment.