Add test for Plugins.showInstalled

This commit is contained in:
Peter Jaszkowiak
2017-07-19 11:38:51 -06:00
parent ee5895f534
commit dc324b36b2
10 changed files with 31 additions and 5 deletions

View File

@@ -297,25 +297,26 @@ Plugins.normalise = function (apiReturn, callback) {
});
};
Plugins.nodeModulesPath = path.join(__dirname, '../node_modules');
Plugins.showInstalled = function (callback) {
var nodeModulesPath = path.join(__dirname, '../node_modules');
var pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
async.waterfall([
function (next) {
fs.readdir(nodeModulesPath, next);
fs.readdir(Plugins.nodeModulesPath, next);
},
function (dirs, next) {
var pluginPaths = [];
async.each(dirs, function (dirname, next) {
var dirPath = path.join(nodeModulesPath, dirname);
var dirPath = path.join(Plugins.nodeModulesPath, dirname);
async.waterfall([
function (cb) {
fs.stat(dirPath, function (err, stats) {
if (err && err.code !== 'ENOENT') {
return next(err);
return cb(err);
}
if (err || !stats.isDirectory()) {
return next();
@@ -361,7 +362,7 @@ Plugins.showInstalled = function (callback) {
function (dirs, next) {
dirs = dirs.map(function (dir) {
return path.join(nodeModulesPath, dir);
return path.join(Plugins.nodeModulesPath, dir);
});
var plugins = [];

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1 @@
{}

View File

@@ -94,6 +94,23 @@ describe('Plugins', function () {
});
});
it('should show installed plugins', function (done) {
var nodeModulesPath = plugins.nodeModulesPath;
plugins.nodeModulesPath = path.join(__dirname, './mocks/plugin_modules');
plugins.showInstalled(function (err, pluginsData) {
assert.ifError(err);
var paths = pluginsData.map(function (plugin) {
return path.relative(plugins.nodeModulesPath, plugin.path).replace(/\\/g, '/');
});
assert(paths.indexOf('nodebb-plugin-xyz') > -1);
assert(paths.indexOf('@nodebb/nodebb-plugin-abc') > -1);
plugins.nodeModulesPath = nodeModulesPath;
done();
});
});
describe('install/activate/uninstall', function () {
var latest;
var pluginName = 'nodebb-plugin-imgur';