mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
Add test for Plugins.showInstalled
This commit is contained in:
@@ -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 = [];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
test/mocks/plugin_modules/nodebb-plugin-xyz/package.json
Normal file
1
test/mocks/plugin_modules/nodebb-plugin-xyz/package.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
test/mocks/plugin_modules/nodebb-plugin-xyz/plugin.json
Normal file
1
test/mocks/plugin_modules/nodebb-plugin-xyz/plugin.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
test/mocks/plugin_modules/something-else/package.json
Normal file
1
test/mocks/plugin_modules/something-else/package.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
1
test/mocks/plugin_modules/something-else/plugin.json
Normal file
1
test/mocks/plugin_modules/something-else/plugin.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
@@ -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';
|
||||||
|
|||||||
Reference in New Issue
Block a user