summaryrefslogtreecommitdiffstats
path: root/lib/plugins/__tests__
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/__tests__')
-rw-r--r--lib/plugins/__tests__/findInstalled.js18
-rw-r--r--lib/plugins/__tests__/listAll.js54
-rw-r--r--lib/plugins/__tests__/validatePlugin.js21
3 files changed, 93 insertions, 0 deletions
diff --git a/lib/plugins/__tests__/findInstalled.js b/lib/plugins/__tests__/findInstalled.js
new file mode 100644
index 0000000..956e73f
--- /dev/null
+++ b/lib/plugins/__tests__/findInstalled.js
@@ -0,0 +1,18 @@
+jest.autoMockOff();
+
+var path = require('path');
+
+describe('findInstalled', function() {
+ var findInstalled = require('../findInstalled');
+
+ pit('must list default plugins for gitbook directory', function() {
+ return findInstalled(path.resolve(__dirname, '../../../'))
+ .then(function(plugins) {
+ expect(plugins.size).toBe(7);
+
+ expect(plugins.has('fontsettings')).toBe(true);
+ expect(plugins.has('search')).toBe(true);
+ });
+ });
+
+});
diff --git a/lib/plugins/__tests__/listAll.js b/lib/plugins/__tests__/listAll.js
new file mode 100644
index 0000000..6da5b8d
--- /dev/null
+++ b/lib/plugins/__tests__/listAll.js
@@ -0,0 +1,54 @@
+jest.autoMockOff();
+
+describe('listAll', function() {
+ var listAll = require('../listAll');
+
+ it('must list from string', function() {
+ var plugins = listAll('ga,great');
+
+ expect(plugins.size).toBe(8);
+
+ expect(plugins.has('ga')).toBe(true);
+ expect(plugins.has('great')).toBe(true);
+
+ expect(plugins.has('search')).toBe(true);
+ });
+
+ it('must list from array', function() {
+ var plugins = listAll(['ga', 'great']);
+
+ expect(plugins.size).toBe(8);
+
+ expect(plugins.has('ga')).toBe(true);
+ expect(plugins.has('great')).toBe(true);
+
+ expect(plugins.has('search')).toBe(true);
+ });
+
+ it('must parse version (semver)', function() {
+ var plugins = listAll(['ga@1.0.0', 'great@>=4.0.0']);
+
+ expect(plugins.has('ga')).toBe(true);
+ expect(plugins.has('great')).toBe(true);
+
+ var ga = plugins.get('ga');
+ expect(ga.getVersion()).toBe('1.0.0');
+
+ var great = plugins.get('great');
+ expect(great.getVersion()).toBe('>=4.0.0');
+ });
+
+ it('must parse version (git)', function() {
+ var plugins = listAll(['ga@git+https://github.com/GitbookIO/plugin-ga.git', 'great@git+ssh://samy@github.com/GitbookIO/plugin-ga.git']);
+
+ expect(plugins.has('ga')).toBe(true);
+ expect(plugins.has('great')).toBe(true);
+
+ var ga = plugins.get('ga');
+ expect(ga.getVersion()).toBe('git+https://github.com/GitbookIO/plugin-ga.git');
+
+ var great = plugins.get('great');
+ expect(great.getVersion()).toBe('git+ssh://samy@github.com/GitbookIO/plugin-ga.git');
+ });
+
+});
diff --git a/lib/plugins/__tests__/validatePlugin.js b/lib/plugins/__tests__/validatePlugin.js
new file mode 100644
index 0000000..3d50839
--- /dev/null
+++ b/lib/plugins/__tests__/validatePlugin.js
@@ -0,0 +1,21 @@
+jest.autoMockOff();
+
+var Promise = require('../../utils/promise');
+var Plugin = require('../../models/plugin');
+
+
+describe('validatePlugin', function() {
+ var validatePlugin = require('../validatePlugin');
+
+ pit('must not validate a not loaded plugin', function() {
+ var plugin = Plugin.createFromString('test');
+
+ return validatePlugin(plugin)
+ .then(function() {
+ throw new Error('Should not be validate');
+ }, function(err) {
+ return Promise();
+ });
+ });
+
+});