0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/test/unit/validate_all.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-04-19 14:15:28 -05:00
'use strict';
2014-02-01 03:08:48 -05:00
// ensure that all arguments are validated
const assert = require('assert');
const path = require('path');
2014-02-01 03:08:48 -05:00
2017-04-19 14:15:28 -05:00
describe('index.js app', test('index.js'));
2017-06-21 12:02:52 -05:00
describe('index.js app', test('../endpoint/index.js'));
describe('index.js app', test('index.js'));
function test(file) {
return function() {
2017-06-21 12:02:52 -05:00
let requirePath = path.normalize(path.join(__dirname + '/../../src/api/web/', file));
let source = require('fs').readFileSync(requirePath, 'utf8');
2017-04-19 14:15:28 -05:00
let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
let m;
let params = {};
while ((m = very_scary_regexp.exec(source)) != null) {
2017-04-19 14:15:28 -05:00
if (m[1] === 'set') continue;
2017-04-19 14:15:28 -05:00
let inner = m[2].slice(1, m[2].length-1);
var t;
inner.split('/').forEach(function(x) {
t = x.match(/^:([^?:]*)\??$/);
if (m[1] === 'param') {
2017-04-19 14:15:28 -05:00
params[x] = 'ok';
} else if (t) {
2017-04-19 14:15:28 -05:00
params[t[1]] = params[t[1]] || m[0].trim();
}
2017-04-19 14:15:28 -05:00
});
}
Object.keys(params).forEach(function(param) {
it('should validate ":'+param+'"', function() {
2017-04-19 14:15:28 -05:00
assert.equal(params[param], 'ok');
});
});
};
}
2014-02-01 03:08:48 -05:00