Skip to content
This repository was archived by the owner on Mar 11, 2022. It is now read-only.

Commit 75bd345

Browse files
authored
Development (#2)
* Add code and tests * Allow plugins to be loaded from an absolute or relative path * Add test to load a plugin from a custom path
1 parent c4aabeb commit 75bd345

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 4.1.2 (2019-07-29)
2-
- [NEW] Plugins can now be loaded from outside of the 'plugins/' directory
2+
- [FIXED] Plugins can now be loaded from outside of the 'plugins/' directory
33

44
# 4.1.1 (2019-06-17)
55
- [FIXED] Remove unnecessary `npm-cli-login` dependency.

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CloudantClient {
102102
var pluginName = Object.keys(plugin)[0];
103103

104104
try {
105-
Plugin = require('../plugins/' + pluginName);
105+
Plugin = require(self._buildPluginPath(pluginName));
106106
} catch (e) {
107107
throw new Error(`Failed to load plugin - ${e.message}`);
108108
}
@@ -120,7 +120,7 @@ class CloudantClient {
120120
}
121121

122122
try {
123-
Plugin = require('../plugins/' + plugin);
123+
Plugin = require(self._buildPluginPath(plugin));
124124
} catch (e) {
125125
throw new Error(`Failed to load plugin - ${e.message}`);
126126
}

test/client.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ describe('CloudantClient', function() {
102102
assert.equal(cloudantClient._buildPluginPath('/plugins/dummy-plugin'), '/plugins/dummy-plugin');
103103
});
104104

105+
it('load plugin from custom path', function() {
106+
let ownPlugin = 'test/fixtures/testplugin.js';
107+
var cloudantClient = new Client({
108+
plugins: [ ownPlugin ]
109+
});
110+
assert.equal(cloudantClient._plugins.length, 1);
111+
});
112+
105113
it('adds cookie authentication plugin if no other plugins are specified', function() {
106114
var cloudantClient = new Client();
107115
assert.equal(cloudantClient._plugins.length, 1);

test/fixtures/testplugin.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright © 2017, 2018 IBM Corp. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use strict';
15+
16+
const BasePlugin = require('../../plugins/base.js');
17+
18+
class TestPlugin extends BasePlugin {
19+
}
20+
21+
TestPlugin.id = 'test';
22+
23+
module.exports = TestPlugin;

0 commit comments

Comments
 (0)