mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-03 23:09:17 -05:00
test: relocate unit test cli, proxy, utils
This commit is contained in:
parent
ca2e23cf9d
commit
b1eb7c6278
7 changed files with 45 additions and 36 deletions
|
@ -1,14 +1,14 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import startServer from '../../../src/index';
|
import startServer from '../../../../src';
|
||||||
import config from '../partials/config/index';
|
import config from '../../partials/config';
|
||||||
import {DEFAULT_DOMAIN, DEFAULT_PORT, DEFAULT_PROTOCOL} from '../../../src/lib/constants';
|
import {DEFAULT_DOMAIN, DEFAULT_PORT, DEFAULT_PROTOCOL} from '../../../../src/lib/constants';
|
||||||
import {getListListenAddresses} from '../../../src/lib/cli/utils';
|
import {getListListenAddresses} from '../../../../src/lib/cli/utils';
|
||||||
|
|
||||||
const logger = require('../../../src/lib/logger');
|
const logger = require('../../../../src/lib/logger');
|
||||||
|
|
||||||
jest.mock('../../../src/lib/logger', () => ({
|
jest.mock('../../../../src/lib/logger', () => ({
|
||||||
setup: jest.fn(),
|
setup: jest.fn(),
|
||||||
logger: {
|
logger: {
|
||||||
child: jest.fn(),
|
child: jest.fn(),
|
|
@ -1,12 +1,12 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import Config from '../../../src/lib/config';
|
import Config from '../../../../src/lib/config';
|
||||||
import {parseConfigFile} from '../../../src/lib/utils';
|
import {parseConfigFile} from '../../../../src/lib/utils';
|
||||||
import {DEFAULT_REGISTRY, DEFAULT_UPLINK, ROLES, WEB_TITLE} from '../../../src/lib/constants';
|
import {DEFAULT_REGISTRY, DEFAULT_UPLINK, ROLES, WEB_TITLE} from '../../../../src/lib/constants';
|
||||||
|
|
||||||
const resolveConf = (conf) => path.join(__dirname, `../../../conf/${conf}.yaml`);
|
const resolveConf = (conf) => path.join(__dirname, `../../../../conf/${conf}.yaml`);
|
||||||
require('../../../src/lib/logger').setup([]);
|
require('../../../../src/lib/logger').setup([]);
|
||||||
|
|
||||||
const checkDefaultUplink = (config) => {
|
const checkDefaultUplink = (config) => {
|
||||||
expect(_.isObject(config.uplinks[DEFAULT_UPLINK])).toBeTruthy();
|
expect(_.isObject(config.uplinks[DEFAULT_UPLINK])).toBeTruthy();
|
|
@ -3,20 +3,20 @@
|
||||||
import rimRaf from 'rimraf';
|
import rimRaf from 'rimraf';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
import LocalStorage from '../../../src/lib/local-storage';
|
import LocalStorage from '../../../../src/lib/local-storage';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../../src/lib/config';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import configExample from '../partials/config/index';
|
import configExample from '../../partials/config';
|
||||||
import Logger, {setup} from '../../../src/lib/logger';
|
import Logger, {setup} from '../../../../src/lib/logger';
|
||||||
import {readFile} from '../../functional/lib/test.utils';
|
import {readFile} from '../../../functional/lib/test.utils';
|
||||||
import {generatePackageTemplate} from '../../../src/lib/storage-utils';
|
import {generatePackageTemplate} from '../../../../src/lib/storage-utils';
|
||||||
import {generateNewVersion} from '../../lib/utils-test';
|
import {generateNewVersion} from '../../../lib/utils-test';
|
||||||
|
|
||||||
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
|
const readMetadata = (fileName: string = 'metadata') => readFile(`../../unit/partials/${fileName}`);
|
||||||
|
|
||||||
import type {Config, MergeTags} from '@verdaccio/types';
|
import type {Config, MergeTags} from '@verdaccio/types';
|
||||||
import type {IStorage} from '../../../types/index';
|
import type {IStorage} from '../../../../types';
|
||||||
import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../src/lib/constants';
|
import { API_ERROR, HTTP_STATUS, DIST_TAGS} from '../../../../src/lib/constants';
|
||||||
|
|
||||||
setup([]);
|
setup([]);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {normalizePackage, mergeUplinkTimeIntoLocal} from "../../../src/lib/storage-utils";
|
import {normalizePackage, mergeUplinkTimeIntoLocal} from "../../../../src/lib/storage-utils";
|
||||||
import { STORAGE, DIST_TAGS } from '../../../src/lib/constants';
|
import { STORAGE, DIST_TAGS } from '../../../../src/lib/constants';
|
||||||
import {readFile} from "../../functional/lib/test.utils";
|
import {readFile} from "../../../functional/lib/test.utils";
|
||||||
|
|
||||||
import type {Package} from '@verdaccio/types';
|
import type {Package} from '@verdaccio/types';
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
import Storage from '../../../src/lib/up-storage';
|
import Storage from '../../../../src/lib/up-storage';
|
||||||
|
|
||||||
require('../../../src/lib/logger').setup([]);
|
require('../../../../src/lib/logger').setup([]);
|
||||||
|
|
||||||
function setupProxy(host, config, mainconfig) {
|
function setupProxy(host, config, mainConfig) {
|
||||||
config.url = host;
|
config.url = host;
|
||||||
return new Storage(config, mainconfig);
|
|
||||||
|
return new Storage(config, mainConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Use proxy', () => {
|
describe('Use proxy', () => {
|
||||||
test('should work fine without proxy', () => {
|
test('should work fine without proxy', () => {
|
||||||
let x = setupProxy('http://x/x', {}, {});
|
let x = setupProxy('http://x/x', {}, {});
|
||||||
|
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,6 +22,7 @@ describe('Use proxy', () => {
|
||||||
|
|
||||||
test('no_proxy is invalid', () => {
|
test('no_proxy is invalid', () => {
|
||||||
let x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: false}, {});
|
let x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: false}, {});
|
||||||
|
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
||||||
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: null}, {});
|
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: null}, {});
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
||||||
|
@ -31,16 +34,19 @@ describe('Use proxy', () => {
|
||||||
|
|
||||||
test('no_proxy - simple/include', () => {
|
test('no_proxy - simple/include', () => {
|
||||||
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
||||||
|
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('no_proxy - simple/not', () => {
|
test('no_proxy - simple/not', () => {
|
||||||
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
|
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
|
||||||
|
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('no_proxy - various, single string', () => {
|
test('no_proxy - various, single string', () => {
|
||||||
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
|
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
|
||||||
|
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
||||||
x = setupProxy('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
|
x = setupProxy('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
|
@ -56,6 +62,7 @@ describe('Use proxy', () => {
|
||||||
|
|
||||||
test('no_proxy - various, array', () => {
|
test('no_proxy - various, array', () => {
|
||||||
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
||||||
|
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
||||||
x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
|
@ -71,6 +78,7 @@ describe('Use proxy', () => {
|
||||||
|
|
||||||
test('no_proxy - hostport', () => {
|
test('no_proxy - hostport', () => {
|
||||||
let x = setupProxy('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
let x = setupProxy('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
||||||
|
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
x = setupProxy('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
x = setupProxy('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
|
@ -78,6 +86,7 @@ describe('Use proxy', () => {
|
||||||
|
|
||||||
test('no_proxy - secure', () => {
|
test('no_proxy - secure', () => {
|
||||||
let x = setupProxy('https://something', {http_proxy: '123'}, {});
|
let x = setupProxy('https://something', {http_proxy: '123'}, {});
|
||||||
|
|
||||||
expect(x.proxy).toEqual(undefined);
|
expect(x.proxy).toEqual(undefined);
|
||||||
x = setupProxy('https://something', {https_proxy: '123'}, {});
|
x = setupProxy('https://something', {https_proxy: '123'}, {});
|
||||||
expect(x.proxy).toEqual('123');
|
expect(x.proxy).toEqual('123');
|
|
@ -1,16 +1,16 @@
|
||||||
// @flow
|
// @flow
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import ProxyStorage from '../../../src/lib/up-storage';
|
import ProxyStorage from '../../../../src/lib/up-storage';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../../src/lib/config';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import configExample from '../partials/config/index';
|
import configExample from '../../partials/config';
|
||||||
import {setup} from '../../../src/lib/logger';
|
import {setup} from '../../../../src/lib/logger';
|
||||||
|
|
||||||
import type {Config, UpLinkConf} from '@verdaccio/types';
|
import type {Config, UpLinkConf} from '@verdaccio/types';
|
||||||
import type {IProxy} from '../../../types/index';
|
import type {IProxy} from '../../../../types';
|
||||||
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
import {API_ERROR, HTTP_STATUS} from "../../../../src/lib/constants";
|
||||||
import {mockServer} from '../__helper/mock';
|
import {mockServer} from '../../__helper/mock';
|
||||||
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
|
||||||
|
|
||||||
setup([]);
|
setup([]);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
let assert = require('assert');
|
let assert = require('assert');
|
||||||
let parseInterval = require('../../../src/lib/utils').parseInterval;
|
let parseInterval = require('../../../../src/lib/utils').parseInterval;
|
||||||
|
|
||||||
describe('Parse interval', () => {
|
describe('Parse interval', () => {
|
||||||
function add_test(str, res) {
|
function add_test(str, res) {
|
Loading…
Add table
Reference in a new issue