mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
var path = require('path');
|
|
var _ = require('lodash');
|
|
var assert = require('assert');
|
|
var fs = require("fs");
|
|
|
|
var Plugin = require("../lib/plugin");
|
|
|
|
var PLUGINS_ROOT = path.resolve(__dirname, "plugins");
|
|
|
|
describe('Plugins', function () {
|
|
describe('invalid plugin', function() {
|
|
it('should signal as invalid', function() {
|
|
var plugin = new Plugin(books[0], "invalid");
|
|
plugin.load("./invalid", PLUGINS_ROOT);
|
|
assert(!plugin.isValid());
|
|
});
|
|
});
|
|
|
|
describe('empty plugin', function() {
|
|
var plugin = new Plugin(books[0], "invalid");
|
|
plugin.load("./empty", PLUGINS_ROOT);
|
|
|
|
it('should valid a plugin', function() {
|
|
assert(plugin.isValid());
|
|
});
|
|
|
|
it('should return an empty list of resources', function(done) {
|
|
qdone(
|
|
plugin.getResources()
|
|
.then(function(resources) {
|
|
_.each(Plugin.RESOURCES, function(resName) {
|
|
assert.equal(resources[resName].length, 0);
|
|
});
|
|
}),
|
|
done);
|
|
});
|
|
});
|
|
|
|
describe('filters', function() {
|
|
var plugin = new Plugin(books[0], "filters");
|
|
plugin.load("./filters", PLUGINS_ROOT);
|
|
|
|
before(function(done) {
|
|
qdone(books[0].plugins.load(plugin), done);
|
|
});
|
|
|
|
it('should valid a plugin', function() {
|
|
assert(plugin.isValid());
|
|
});
|
|
|
|
it('should return a map of filters', function() {
|
|
var filters = plugin.getFilters();
|
|
assert.equal(_.size(filters), 2);
|
|
assert(filters["hello"]);
|
|
assert(filters["helloCtx"]);
|
|
});
|
|
|
|
it('should correctly extend template filters', function(done) {
|
|
qdone(
|
|
books[0].template.renderString('{{ "World"|hello }}')
|
|
.then(function(content) {
|
|
assert.equal(content, "Hello World");
|
|
}),
|
|
done
|
|
);
|
|
});
|
|
|
|
it('should correctly set book as context', function(done) {
|
|
qdone(
|
|
books[0].template.renderString('{{ "root"|helloCtx }}')
|
|
.then(function(content) {
|
|
assert.equal(content, "root:"+books[0].root);
|
|
}),
|
|
done
|
|
);
|
|
});
|
|
});
|
|
});
|