diff options
-rw-r--r-- | lib/plugins/index.js | 3 | ||||
-rw-r--r-- | test/mock.js | 8 | ||||
-rw-r--r-- | test/plugins.js | 38 |
3 files changed, 41 insertions, 8 deletions
diff --git a/lib/plugins/index.js b/lib/plugins/index.js index 9642b4b..6eb788b 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -79,6 +79,7 @@ PluginsManager.prototype._setup = function(plugin) { // Install all plugins for the book PluginsManager.prototype.install = function() { + var that = this; var plugins = _.filter(this.book.config.get('plugins'), { isDefault: false }); @@ -91,7 +92,7 @@ PluginsManager.prototype.install = function() { this.log.info.ln('installing', plugins.length, 'plugins'); return Promise.serie(plugins, function(plugin) { - return registry.install(plugin.name, plugin.version); + return registry.install(that.book, plugin.name, plugin.version); }) .thenResolve(plugins.length); diff --git a/test/mock.js b/test/mock.js index ce4dca5..701df99 100644 --- a/test/mock.js +++ b/test/mock.js @@ -78,8 +78,14 @@ function outputDefaultBook(Output, files, summary, opts) { }); } +// Log an error +function logError(err) { + console.log(err.stack || err); +} + module.exports = { setupBook: setupBook, setupDefaultBook: setupDefaultBook, - outputDefaultBook: outputDefaultBook + outputDefaultBook: outputDefaultBook, + logError: logError }; diff --git a/test/plugins.js b/test/plugins.js index 81c099e..47f9314 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -1,6 +1,7 @@ var mock = require('./mock'); var registry = require('../lib/plugins/registry'); var Output = require('../lib/output/base'); +var PluginsManager = require('../lib/plugins'); describe('Plugins', function() { var book; @@ -19,6 +20,15 @@ describe('Plugins', function() { }); }); + describe('Loading', function() { + it('should load default plugins', function() { + return mock.outputDefaultBook(Output) + .then(function(output) { + output.plugins.count().should.be.greaterThan(0); + }); + }); + }); + describe('Installation', function() { it('should install a plugin from NPM without a specific version', function() { return registry.install(book, 'ga') @@ -29,15 +39,31 @@ describe('Plugins', function() { return registry.install(book, 'ga', '1.0.0') .should.be.fulfilled(); }); - }); - describe('Loading', function() { - it('should load default plugins', function() { - return mock.outputDefaultBook(Output) - .then(function(output) { - output.plugins.count().should.be.greaterThan(0); + it('should correctly install all dependencies (if none)', function() { + return mock.setupBook({}) + .then(function(book) { + var plugins = new PluginsManager(book); + return plugins.install() + .should.be.fulfilledWith(0); }); }); + + it('should correctly install all dependencies (if any)', function() { + return mock.setupBook({ + 'book.json': { + plugins: ['ga'] + } + }) + .then(function(book) { + return book.config.load() + .then(function() { + var plugins = new PluginsManager(book); + return plugins.install(); + }); + }) + .should.be.fulfilledWith(1); + }); }); }); |