2018-06-28 18:33:37 +02:00
|
|
|
import path from 'path';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
import startServer from '../../../src/index';
|
|
|
|
import {getListListenAddresses} from '../../../src/lib/bootstrap';
|
|
|
|
import config from '../partials/config/index';
|
2018-06-28 22:17:38 +02:00
|
|
|
import {DEFAULT_DOMAIN, DEFAULT_PORT} from '../../../src/lib/constants';
|
2018-01-17 22:29:00 +01:00
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
require('../../../src/lib/logger').setup([]);
|
2018-01-17 22:29:00 +01:00
|
|
|
|
|
|
|
describe('startServer via API', () => {
|
|
|
|
|
|
|
|
describe('startServer launcher', () => {
|
2018-04-21 18:36:06 +02:00
|
|
|
test('should provide all server data await/async', async (done) => {
|
2018-01-17 22:29:00 +01:00
|
|
|
const store = path.join(__dirname, 'partials/store');
|
2018-06-28 18:33:37 +02:00
|
|
|
const serverName = 'verdaccio-test';
|
|
|
|
const version = '1.0.0';
|
|
|
|
const port = '6000';
|
2018-01-17 22:29:00 +01:00
|
|
|
|
2018-06-28 18:33:37 +02:00
|
|
|
await startServer(config, port, store, version, serverName,
|
2018-01-17 22:29:00 +01:00
|
|
|
(webServer, addrs, pkgName, pkgVersion) => {
|
|
|
|
expect(webServer).toBeDefined();
|
|
|
|
expect(addrs).toBeDefined();
|
|
|
|
expect(addrs.proto).toBe('http');
|
|
|
|
expect(addrs.host).toBe('localhost');
|
2018-06-28 18:33:37 +02:00
|
|
|
expect(addrs.port).toBe(port);
|
2018-01-17 22:29:00 +01:00
|
|
|
expect(pkgName).toBeDefined();
|
|
|
|
expect(pkgVersion).toBeDefined();
|
2018-06-28 18:33:37 +02:00
|
|
|
expect(pkgVersion).toBe(version);
|
|
|
|
expect(pkgName).toBe(serverName);
|
2018-01-17 22:29:00 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-21 18:36:06 +02:00
|
|
|
test('should fails if config is missing', async () => {
|
|
|
|
try {
|
|
|
|
await startServer();
|
|
|
|
} catch (e) {
|
|
|
|
expect(e.message).toEqual('config file must be an object');
|
|
|
|
}
|
2018-01-17 22:29:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getListListenAddresses test', () => {
|
2018-06-28 22:17:38 +02:00
|
|
|
test(`should return by default ${DEFAULT_PORT}`, () => {
|
2018-01-17 22:29:00 +01:00
|
|
|
const addrs = getListListenAddresses()[0];
|
|
|
|
|
|
|
|
expect(addrs.proto).toBe('http');
|
2018-06-28 22:17:38 +02:00
|
|
|
expect(addrs.host).toBe(DEFAULT_DOMAIN);
|
|
|
|
expect(addrs.port).toBe(DEFAULT_PORT);
|
2018-01-17 22:29:00 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return a list of address and no cli argument provided', () => {
|
|
|
|
const addrs = getListListenAddresses(null, ['1000', '2000']);
|
|
|
|
|
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should return an address and no cli argument provided', () => {
|
|
|
|
const addrs = getListListenAddresses(null, '1000');
|
|
|
|
|
|
|
|
expect(_.isArray(addrs)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|