1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/api/cli.spec.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-06-28 18:33:37 +02:00
import path from 'path';
import _ from 'lodash';
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';
require('../../../src/lib/logger').setup([]);
describe('startServer via API', () => {
describe('startServer launcher', () => {
test('should provide all server data await/async', async (done) => {
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-06-28 18:33:37 +02:00
await startServer(config, port, store, version, serverName,
(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);
expect(pkgName).toBeDefined();
expect(pkgVersion).toBeDefined();
2018-06-28 18:33:37 +02:00
expect(pkgVersion).toBe(version);
expect(pkgName).toBe(serverName);
done();
});
});
test('should fails if config is missing', async () => {
try {
await startServer();
} catch (e) {
expect(e.message).toEqual('config file must be an object');
}
});
});
describe('getListListenAddresses test', () => {
2018-06-28 22:17:38 +02:00
test(`should return by default ${DEFAULT_PORT}`, () => {
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);
});
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();
});
});
});