Add test for Plugins.showInstalled

v1.18.x
Peter Jaszkowiak 8 years ago
parent ee5895f534
commit dc324b36b2

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

@ -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 () { describe('install/activate/uninstall', function () {
var latest; var latest;
var pluginName = 'nodebb-plugin-imgur'; var pluginName = 'nodebb-plugin-imgur';

Loading…
Cancel
Save