mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-17 23:45:29 -05:00
Add unit test for plugin-loader
This commit is contained in:
parent
d11d9ea5a4
commit
7df6962f43
8 changed files with 130 additions and 0 deletions
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "invalid-package",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
function ValidVerdaccioPlugin() {
|
||||||
|
return {
|
||||||
|
// not valid method
|
||||||
|
authenticate__: function(){}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = ValidVerdaccioPlugin;
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "invalid-plugin-sanity",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
module.exports = {};
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "invalid-plugin",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
function ValidVerdaccioPlugin() {
|
||||||
|
return {
|
||||||
|
authenticate: function(){}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = ValidVerdaccioPlugin;
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "verdaccio-plugin",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
70
test/unit/plugin_loader.js
Normal file
70
test/unit/plugin_loader.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const load_plugins = require('../../lib/plugin-loader').load_plugins;
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
describe('plugin loader', function() {
|
||||||
|
|
||||||
|
it('testing auth valid plugin loader', function() {
|
||||||
|
let _config = {
|
||||||
|
self_path: path.join(__dirname, './'),
|
||||||
|
max_users: 0,
|
||||||
|
auth: {
|
||||||
|
'./unit/partials/test-plugin-storage/verdaccio-plugin': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let p = load_plugins(_config, _config.auth, {}, function (p) {
|
||||||
|
return p.authenticate || p.allow_access || p.allow_publish;
|
||||||
|
});
|
||||||
|
assert(p.length === 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('testing auth plugin invalid plugin', function() {
|
||||||
|
let _config = {
|
||||||
|
self_path: path.join(__dirname, './'),
|
||||||
|
auth: {
|
||||||
|
'./unit/partials/test-plugin-storage/invalid-plugin': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
load_plugins(_config, _config.auth, {}, function (p) {
|
||||||
|
return p.authenticate || p.allow_access || p.allow_publish;
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin" doesn\'t look like a valid plugin');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('testing auth plugin invalid plugin sanityCheck', function() {
|
||||||
|
let _config = {
|
||||||
|
self_path: path.join(__dirname, './'),
|
||||||
|
auth: {
|
||||||
|
'./unit/partials/test-plugin-storage/invalid-plugin-sanity': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
load_plugins(_config, _config.auth, {}, function (p) {
|
||||||
|
return p.authenticate || p.allow_access || p.allow_publish;
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
assert(e.message === '"./unit/partials/test-plugin-storage/invalid-plugin-sanity" doesn\'t look like a valid plugin');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('testing auth plugin no plugins', function() {
|
||||||
|
let _config = {
|
||||||
|
auth: {
|
||||||
|
'./unit/partials/test-plugin-storage/invalid-package': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
load_plugins(_config, _config.auth, {}, function (p) {
|
||||||
|
return p.authenticate || p.allow_access || p.allow_publish;
|
||||||
|
});
|
||||||
|
} catch(e) {
|
||||||
|
assert(e.message === `"./unit/partials/test-plugin-storage/invalid-package" plugin not found\ntry "npm install verdaccio-./unit/partials/test-plugin-storage/invalid-package"`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue