Add tests for installation of plugins

This commit is contained in:
Samy Pessé
2016-02-17 12:55:46 +01:00
parent e2c21051aa
commit e95678cf3a
3 changed files with 41 additions and 8 deletions
+2 -1
View File
@@ -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);
+7 -1
View File
@@ -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
};
+32 -6
View File
@@ -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);
});
});
});