1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00

test: relocate spec test

This commit is contained in:
Juan Picado @jotadeveloper 2019-05-19 22:23:12 +02:00
parent 2f3ec2ce42
commit b4c42c1a78
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
32 changed files with 69 additions and 31 deletions

@ -405,7 +405,7 @@ class ProxyStorage implements IProxy {
const headers = {};
if (_.isNil(options.etag) === false) {
headers['If-None-Match'] = options.etag;
headers['Accept'] = contentTypeAccept;
headers[HEADERS.ACCEPT] = contentTypeAccept;
}
this.request(

@ -8,6 +8,44 @@ import Server from '../../lib/server';
import type {IServerBridge} from '../../types';
/**
* Fork a Verdaccio process with a custom configuration.
*
* Usage:
*
* - Fork the process within the beforeAll body.
* - Define a storage (use a specific name)
* - Define a unique port (be careful with conflicts)
* - Set a configuration
* - await / mockServer
* - call done();
*
* beforeAll(function(done) {
const store = path.join(__dirname, '../partials/store/test-profile-storage');
const mockServerPort = 55544;
rimraf(store, async () => {
const parsedConfig = parseConfigFile(parseConfigurationProfile());
const configForTest = _.assign({}, _.cloneDeep(parsedConfig), {
storage: store,
auth: {
htpasswd: {
file: './test-profile-storage/.htpasswd'
}
},
self_path: store
});
app = await endPointAPI(configForTest);
mockRegistry = await mockServer(mockServerPort).init();
done();
});
On finish the test we must close the server
afterAll(function(done) {
mockRegistry[0].stop();
done();
});
*
*
* @param port
* @returns {VerdaccioProcess}

@ -3,26 +3,27 @@ import _ from 'lodash';
import path from 'path';
import rimraf from 'rimraf';
import { HEADERS, HTTP_STATUS } from '../../../src/lib/constants';
import configDefault from '../partials/config/config_access';
import endPointAPI from '../../../src/api/index';
import {mockServer} from '../__helper/mock';
import {DOMAIN_SERVERS} from '../../functional/config.functional';
import { HEADERS, HTTP_STATUS } from '../../../../src/lib/constants';
import configDefault from '../../partials/config/config_access';
import endPointAPI from '../../../../src/api';
import {mockServer} from '../../__helper/mock';
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
require('../../../src/lib/logger').setup([]);
require('../../../../src/lib/logger').setup([]);
describe('api with no limited access configuration', () => {
let app;
let mockRegistry;
const store = path.join(__dirname, '../../partials/store/pkg-access-spec');
beforeAll(function(done) {
const mockServerPort = 55530;
const store = path.join(__dirname, './partials/store/access-storage');
rimraf(store, async () => {
const configForTest = _.assign({}, _.cloneDeep(configDefault), {
auth: {
htpasswd: {
file: './access-storage/htpasswd-access-test'
file: './access-storage/htpasswd-pkg-access'
}
},
self_path: store,
@ -40,7 +41,6 @@ describe('api with no limited access configuration', () => {
});
afterAll(function(done) {
const store = path.join(__dirname, './partials/store/access-storage');
rimraf(store, (err) => {
if (err) {
mockRegistry[0].stop();

@ -5,16 +5,16 @@ import _ from 'lodash';
import path from 'path';
import rimraf from 'rimraf';
import endPointAPI from '../../../src/api/index';
import endPointAPI from '../../../../src/api';
import {HEADERS, HTTP_STATUS, HEADER_TYPE, TOKEN_BEARER, TOKEN_BASIC} from '../../../src/lib/constants';
import {mockServer} from '../__helper/mock';
import {DOMAIN_SERVERS} from '../../functional/config.functional';
import {buildToken, parseConfigFile} from '../../../src/lib/utils';
import {parseConfigurationFile} from '../__helper';
import {addUser, getPackage} from '../__helper/api';
import {setup} from '../../../src/lib/logger';
import {buildUserBuffer} from '../../../src/lib/auth-utils';
import {HEADERS, HTTP_STATUS, HEADER_TYPE, TOKEN_BEARER, TOKEN_BASIC} from '../../../../src/lib/constants';
import {mockServer} from '../../__helper/mock';
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
import {buildToken, parseConfigFile} from '../../../../src/lib/utils';
import {parseConfigurationFile} from '../../__helper';
import {addUser, getPackage} from '../../__helper/api';
import {setup} from '../../../../src/lib/logger';
import {buildUserBuffer} from '../../../../src/lib/auth-utils';
setup([]);
const credentials = { name: 'JotaJWT', password: 'secretPass' };
@ -31,13 +31,13 @@ describe('endpoint user auth JWT unit test', () => {
const FAKE_TOKEN: string = buildToken(TOKEN_BEARER, 'fake');
beforeAll(function(done) {
const store = path.join(__dirname, '../partials/store/test-jwt-storage');
const store = path.join(__dirname, '../../partials/store/test-jwt-storage');
const mockServerPort = 55546;
rimraf(store, async () => {
const confS = parseConfigFile(parseConfigurationJWTFile());
const configForTest = _.assign({}, _.cloneDeep(confS), {
storage: store,
plinks: {
uplinks: {
npmjs: {
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
}
@ -45,7 +45,7 @@ describe('endpoint user auth JWT unit test', () => {
self_path: store,
auth: {
htpasswd: {
file: './test-jwt-storage/.htpasswd'
file: './test-jwt-storage/.htpasswd_jwt_auth'
}
}
});

@ -5,13 +5,13 @@ import _ from 'lodash';
import path from 'path';
import rimraf from 'rimraf';
import endPointAPI from '../../../src/api/index';
import {mockServer} from '../__helper/mock';
import {parseConfigFile} from '../../../src/lib/utils';
import {parseConfigurationFile} from '../__helper';
import {getNewToken, getProfile, postProfile} from '../__helper/api';
import {setup} from '../../../src/lib/logger';
import {API_ERROR, HTTP_STATUS, SUPPORT_ERRORS} from '../../../src/lib/constants';
import endPointAPI from '../../../../src/api';
import {mockServer} from '../../__helper/mock';
import {parseConfigFile} from '../../../../src/lib/utils';
import {parseConfigurationFile} from '../../__helper';
import {getNewToken, getProfile, postProfile} from '../../__helper/api';
import {setup} from '../../../../src/lib/logger';
import {API_ERROR, HTTP_STATUS, SUPPORT_ERRORS} from '../../../../src/lib/constants';
setup([]);
@ -25,7 +25,7 @@ describe('endpoint user profile', () => {
let mockRegistry;
beforeAll(function(done) {
const store = path.join(__dirname, '../partials/store/test-profile-storage');
const store = path.join(__dirname, '../../partials/store/test-profile-storage');
const mockServerPort = 55544;
rimraf(store, async () => {
const parsedConfig = parseConfigFile(parseConfigurationProfile());
@ -33,7 +33,7 @@ describe('endpoint user profile', () => {
storage: store,
auth: {
htpasswd: {
file: './test-profile-storage/.htpasswd'
file: './test-profile-storage/.htpasswd-auth-profile'
}
},
self_path: store