1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/modules/api/validate.api.params.middleware.spec.ts
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

42 lines
1.2 KiB
TypeScript

// ensure that all arguments are validated
import path from 'path';
import fs from 'fs';
/**
* Validate.
app.param('package', validate_pkg);
app.param('filename', validate_name);
app.param('tag', validate_name);
app.param('version', validate_name);
app.param('revision', validate_name);
app.param('token', validate_name);
*/
describe('api endpoint app.param()', () => {
const file = '../endpoint/index.ts';
let m;
const requirePath = path.normalize(path.join(__dirname + '/../../../../src/api/web/', file));
const source = fs.readFileSync(requirePath, 'utf8');
const very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
const appParams = {};
while ((m = very_scary_regexp.exec(source)) != null) {
if (m[1] === 'set') continue;
let inner = m[2].slice(1, m[2].length-1);
var t;
inner.split('/').forEach(function(x) {
t = x.match(/^:([^?:]*)\??$/);
if (m[1] === 'param') {
appParams[x] = 'ok';
} else if (t) {
appParams[t[1]] = appParams[t[1]] || m[0].trim();
}
});
}
test.each(Object.keys(appParams))('should validate ":%s"', (param) => {
expect(appParams[param]).toEqual('ok');
});
});