1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-17 07:45:52 +01:00
verdaccio/test/unit/modules/cli/parseAddress.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

52 lines
1.7 KiB
TypeScript

import _ from 'lodash';
import {parseAddress as parse} from '../../../../src/lib/utils';
import {DEFAULT_DOMAIN, DEFAULT_PORT} from '../../../../src/lib/constants';
describe('Parse listen address', () => {
const useCases = [];
function addTest(uri, proto, host?, port?) {
useCases.push([uri, proto, host, port]);
}
addTest(DEFAULT_PORT, 'http', DEFAULT_DOMAIN, DEFAULT_PORT);
addTest(':4873', 'http', DEFAULT_DOMAIN, DEFAULT_PORT);
addTest('blah:4873', 'http', 'blah', DEFAULT_PORT);
addTest('http://:4873', 'http', DEFAULT_DOMAIN, DEFAULT_PORT);
addTest('https::4873', 'https', DEFAULT_DOMAIN, DEFAULT_PORT);
addTest('https:blah:4873', 'https', 'blah', DEFAULT_PORT);
addTest('https://blah:4873/', 'https', 'blah', DEFAULT_PORT);
addTest('[::1]:4873', 'http', '::1', DEFAULT_PORT);
addTest('https:[::1]:4873', 'https', '::1', DEFAULT_PORT);
addTest('unix:/tmp/foo.sock', 'http', '/tmp/foo.sock');
addTest('http:unix:foo.sock', 'http', 'foo.sock');
addTest('https://unix:foo.sock', 'https', 'foo.sock');
addTest('https://unix:foo.sock:34', 'https', 'foo.sock:34');
addTest('http://foo.sock:34', 'http', 'foo.sock', '34');
addTest('blah', null);
addTest('blah://4873', null);
addTest('https://blah:4873///', null);
addTest('unix:1234', 'http', 'unix', '1234'); // not unix socket
test.each(useCases)(`should parse (%s - %s - %s - %s)`, (uri, proto, host, port) => {
const parsed = parse(uri);
if (_.isNull(proto)) {
expect(parsed).toBeNull();
} else if (port) {
expect(parsed).toEqual({
proto,
host,
port,
});
} else {
expect(parsed).toEqual({
proto,
path: host,
});
}
});
});