mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-24 21:15:51 +01:00
refactor: improve code with es6 style
This commit is contained in:
parent
32e64c0fe3
commit
3f5a5c2345
@ -39,7 +39,7 @@ test/
|
||||
__mocks__/
|
||||
jestEnvironment.js
|
||||
test/jest.e2e.config.js
|
||||
test/jest.config.func.js
|
||||
test/jest.config.functional.js
|
||||
jest.config.unit.js
|
||||
|
||||
|
||||
|
@ -156,7 +156,7 @@
|
||||
"pretest": "npm run code:build",
|
||||
"test": "npm run test:unit",
|
||||
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest --config ./jest.config.unit.js --maxWorkers 2",
|
||||
"test:functional": "cross-env NODE_ENV=testOldEnv jest --config ./test/jest.config.func.js --testPathPattern ./test/functional/index*",
|
||||
"test:functional": "cross-env NODE_ENV=testOldEnv jest --config ./test/jest.config.functional.js --testPathPattern ./test/functional/index*",
|
||||
"test:e2e": "cross-env BABEL_ENV=testOldEnv jest --config ./test/jest.config.e2e.js",
|
||||
"test:all": "npm run test && npm run test:functional && npm run test:e2e",
|
||||
"pre:ci": "npm run lint && npm run build:webui",
|
||||
|
@ -53,9 +53,9 @@ class Auth {
|
||||
}
|
||||
|
||||
if (user.name) {
|
||||
cb(ErrorCode.getForbidden('user ' + user.name + ' is not allowed to ' + action + ' package ' + pkg.name));
|
||||
cb(ErrorCode.getForbidden(`user ${user.name} is not allowed to ${action} package ${pkg.name}`));
|
||||
} else {
|
||||
cb(ErrorCode.getForbidden('unregistered users are not allowed to ' + action + ' package ' + pkg.name));
|
||||
cb(ErrorCode.getForbidden(`unregistered users are not allowed to ${action} package ${pkg.name}`));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -52,7 +52,7 @@ export const API_ERROR = {
|
||||
NOT_ALLOWED: 'not allowed to access package',
|
||||
INTERNAL_SERVER_ERROR: 'internal server error',
|
||||
UNKNOWN_ERROR: 'unknown error',
|
||||
NOT_PACKAGE_UPLINK: 'package doesn\'t exist on uplink',
|
||||
NOT_PACKAGE_UPLINK: 'package does not exist on uplink',
|
||||
CONTENT_MISMATCH: 'content length mismatch',
|
||||
NOT_FILE_UPLINK: 'file doesn\'t exist on uplink',
|
||||
MAX_USERS_REACHED: 'maximum amount of users reached',
|
||||
|
@ -467,12 +467,8 @@ function parseReadme(packageName: string, readme: string): string {
|
||||
return marked('ERROR: No README data found!');
|
||||
}
|
||||
|
||||
export function capitalizeFirstLetter(character: string) {
|
||||
return character[0].toUpperCase() + character.slice(1);
|
||||
}
|
||||
|
||||
export function buildToken(type: string, token: string) {
|
||||
return `${capitalizeFirstLetter(type)} ${token}`;
|
||||
return `${_.capitalize(type)} ${token}`;
|
||||
}
|
||||
|
||||
export {
|
||||
|
@ -1,3 +1,3 @@
|
||||
require("babel-polyfill");
|
||||
require('babel-polyfill');
|
||||
require('babel-register');
|
||||
module.exports = require('./setup');
|
||||
|
@ -4,7 +4,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import {CREDENTIALS, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.func";
|
||||
import {CREDENTIALS, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.functional";
|
||||
import whoIam from './whoIam';
|
||||
import ping from './ping';
|
||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||
@ -125,10 +125,6 @@ export default function(server: any, server2: any) {
|
||||
.body_ok(/published/);
|
||||
});
|
||||
|
||||
test('uploading new package version', () => {
|
||||
/* test for before() */
|
||||
});
|
||||
|
||||
describe('should download a package', () => {
|
||||
beforeAll(function() {
|
||||
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {CREDENTIALS} from "../config.func";
|
||||
import {CREDENTIALS} from "../config.functional";
|
||||
|
||||
module.exports = function(server) {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
|
||||
|
||||
module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= `http://${DOMAIN_SERVERS}:${port}`,
|
||||
fileName = TARBALL, readme = 'this is a readme') {
|
||||
|
29
test/functional/fixtures/publish.json
Normal file
29
test/functional/fixtures/publish.json
Normal file
@ -0,0 +1,29 @@
|
||||
{ _id: "__NAME__",
|
||||
name: "__NAME__",
|
||||
description: "",
|
||||
"dist-tags": { latest: "__VERSION__" },
|
||||
versions:
|
||||
{ "__VERSION__":
|
||||
{ name: "__NAME__",
|
||||
version: "__VERSION__",
|
||||
description: "",
|
||||
main: "index.js",
|
||||
scripts: { test: "echo "Error: no test specified" && exit 1" },
|
||||
author: "",
|
||||
license: "ISC",
|
||||
readme: "ERROR: No README data found!",
|
||||
_id: "__NAME__@__VERSION__",
|
||||
dist:
|
||||
{ shasum: "071c8dd9fd775bf3ebc0d5108431110f5f857ce3",
|
||||
tarball: "http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz" },
|
||||
_from: ".",
|
||||
_npmVersion: "1.3.21",
|
||||
_npmUser: { name: "username", email: "user@domain.com" },
|
||||
maintainers: [ { name: "username", email: "user@domain.com" } ] } },
|
||||
readme: "ERROR: No README data found!",
|
||||
maintainers: [ { name: "username", email: "user@domain.com" } ],
|
||||
_attachments:
|
||||
{ "__NAME__-__VERSION__.tgz":
|
||||
{ content_type: "application/octet-stream",
|
||||
data: "H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==",
|
||||
length: 250 } } }
|
@ -1,29 +1,27 @@
|
||||
{ _id: '__NAME__',
|
||||
name: '__NAME__',
|
||||
description: '',
|
||||
'dist-tags': { latest: '__VERSION__' },
|
||||
versions:
|
||||
{ '__VERSION__':
|
||||
{ name: '__NAME__',
|
||||
version: '__VERSION__',
|
||||
description: '',
|
||||
main: 'index.js',
|
||||
scripts: { test: 'echo "Error: no test specified" && exit 1' },
|
||||
author: '',
|
||||
license: 'ISC',
|
||||
readme: 'ERROR: No README data found!',
|
||||
_id: '__NAME__@__VERSION__',
|
||||
dist:
|
||||
{ shasum: '071c8dd9fd775bf3ebc0d5108431110f5f857ce3',
|
||||
tarball: 'http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz' },
|
||||
_from: '.',
|
||||
_npmVersion: '1.3.21',
|
||||
_npmUser: { name: 'rlidwka', email: 'user@domain.com' },
|
||||
maintainers: [ { name: 'rlidwka', email: 'user@domain.com' } ] } },
|
||||
readme: 'ERROR: No README data found!',
|
||||
maintainers: [ { name: 'rlidwka', email: 'user@domain.com' } ],
|
||||
_attachments:
|
||||
{ '__NAME__-__VERSION__.tgz':
|
||||
{ content_type: 'application/octet-stream',
|
||||
data: 'H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==',
|
||||
length: 250 } } }
|
||||
{ "_id": "__NAME__",
|
||||
"name": "__NAME__",
|
||||
"dist-tags": { "latest": "__VERSION__" },
|
||||
"versions":
|
||||
{ "__VERSION__":
|
||||
{ "name": "__NAME__",
|
||||
"version": "__VERSION__",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"readme": "ERROR: No README data found!",
|
||||
"_id": "__NAME__@__VERSION__",
|
||||
"dist":
|
||||
{ "shasum": "071c8dd9fd775bf3ebc0d5108431110f5f857ce3",
|
||||
"tarball": "http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz" },
|
||||
"_from": ".",
|
||||
"_npmVersion": "1.3.21",
|
||||
"_npmUser": { "name": "username", "email": "user@domain.com" },
|
||||
"maintainers": [ { "name": "username", "email": "user@domain.com" } ] } },
|
||||
"readme": "ERROR: No README data found!",
|
||||
"maintainers": [ { "name": "username", "email": "user@domain.com" } ],
|
||||
"_attachments":
|
||||
{ "__NAME__-__VERSION__.tgz":
|
||||
{ "content_type": "application/octet-stream",
|
||||
"data": "H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==",
|
||||
"length": 250 } } }
|
||||
|
@ -3,12 +3,12 @@
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
import NodeEnvironment from 'jest-environment-node';
|
||||
import {VerdaccioConfig} from "../../lib/verdaccio-server";
|
||||
import VerdaccioProcess from "../../lib/server_process";
|
||||
import Server from "../../lib/server";
|
||||
import ExpressServer from "./simple_server";
|
||||
import {VerdaccioConfig} from '../../lib/verdaccio-server';
|
||||
import VerdaccioProcess from '../../lib/server_process';
|
||||
import Server from '../../lib/server';
|
||||
import ExpressServer from './simple_server';
|
||||
import type {IServerBridge} from '../../types';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.functional';
|
||||
|
||||
const EXPRESS_PORT = 55550;
|
||||
|
||||
|
@ -8,7 +8,6 @@ export default class ExpressServer {
|
||||
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.server;
|
||||
}
|
||||
|
||||
start(port: number): Promise<any> {
|
||||
|
@ -2,7 +2,7 @@ import _ from 'lodash';
|
||||
|
||||
import {HEADERS} from '../../../src/lib/constants';
|
||||
import {notify} from '../../../src/lib/notify';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||
|
||||
export default function(express) {
|
||||
const config = {
|
||||
@ -126,11 +126,11 @@ export default function(express) {
|
||||
});
|
||||
});
|
||||
|
||||
test("publisher property should not be overridden if it exists in metadata", done => {
|
||||
test('publisher property should not be overridden if it exists in metadata', done => {
|
||||
const metadata = {
|
||||
name: "pkg-test",
|
||||
name: 'pkg-test',
|
||||
publisher: {
|
||||
name: "existing-publisher-name"
|
||||
name: 'existing-publisher-name'
|
||||
}
|
||||
};
|
||||
|
||||
@ -138,7 +138,7 @@ export default function(express) {
|
||||
function(body) {
|
||||
const jsonBody = parseBody(body);
|
||||
expect(`New package published: * ${metadata.name}*. Publisher name: * ${metadata.publisher.name} *.`)
|
||||
.toBe(jsonBody.message, "Body notify message should be equal");
|
||||
.toBe(jsonBody.message, 'Body notify message should be equal');
|
||||
done();
|
||||
},
|
||||
function(err) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {buildToken} from "../../../src/lib/utils";
|
||||
import {HTTP_STATUS, TOKEN_BASIC} from "../../../src/lib/constants";
|
||||
import {CREDENTIALS} from "../config.func";
|
||||
import {API_ERROR, HTTP_STATUS, TOKEN_BASIC} from "../../../src/lib/constants";
|
||||
import {CREDENTIALS} from "../config.functional";
|
||||
|
||||
export default function(server) {
|
||||
|
||||
@ -17,13 +17,14 @@ export default function(server) {
|
||||
*/
|
||||
function checkAccess(auth, pkg, ok) {
|
||||
test(
|
||||
(ok ? 'allows' : 'forbids') + ' access ' + auth + ' to ' + pkg, () => {
|
||||
`${(ok ? 'allows' : 'forbids')} access ${auth} to ${pkg}`, () => {
|
||||
server.authstr = auth ? buildAccesToken(auth) : undefined;
|
||||
const req = server.getPackage(pkg);
|
||||
|
||||
if (ok) {
|
||||
return req.status(HTTP_STATUS.NOT_FOUND).body_error(/no such package available/);
|
||||
return req.status(HTTP_STATUS.NOT_FOUND).body_error(API_ERROR.NO_PACKAGE);
|
||||
} else {
|
||||
return req.status(HTTP_STATUS.FORBIDDEN).body_error(/not allowed to access package/);
|
||||
return req.status(HTTP_STATUS.FORBIDDEN).body_error(API_ERROR.NOT_ALLOWED);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -4,30 +4,25 @@ import {HEADER_TYPE, HEADERS, HTTP_STATUS} from "../../../src/lib/constants";
|
||||
|
||||
export default function(server, express) {
|
||||
const PKG_NAME = 'testexp_gzip';
|
||||
const PKG_VERSION = '0.0.1';
|
||||
const PKG_BAD_DATA = 'testexp_baddata';
|
||||
const VERSION_TOTAL = 4;
|
||||
|
||||
|
||||
describe('test gzip support', () => {
|
||||
beforeAll(function() {
|
||||
express.get(`/${PKG_NAME}`, function(req, res) {
|
||||
const version = '0.0.1';
|
||||
const pkg = eval(
|
||||
'(' + readFile('../fixtures/publish.json5')
|
||||
const pkg = JSON.parse(readFile('../fixtures/publish.json5')
|
||||
.toString('utf8')
|
||||
.replace(/__NAME__/g, PKG_NAME)
|
||||
.replace(/__VERSION__/g, version)
|
||||
+ ')'
|
||||
);
|
||||
.replace(/__VERSION__/g, PKG_VERSION));
|
||||
|
||||
// overcoming compress threshold
|
||||
pkg.versions['0.0.2'] = pkg.versions[version];
|
||||
pkg.versions['0.0.3'] = pkg.versions[version];
|
||||
pkg.versions['0.0.4'] = pkg.versions[version];
|
||||
pkg.versions['0.0.5'] = pkg.versions[version];
|
||||
pkg.versions['0.0.6'] = pkg.versions[version];
|
||||
pkg.versions['0.0.7'] = pkg.versions[version];
|
||||
pkg.versions['0.0.8'] = pkg.versions[version];
|
||||
pkg.versions['0.0.9'] = pkg.versions[version];
|
||||
for (let i = 1; i <= VERSION_TOTAL; i++) {
|
||||
pkg.versions[`0.0.${i}`] = pkg.versions[PKG_VERSION];
|
||||
}
|
||||
|
||||
zlib.gzip(JSON.stringify(pkg), function(err, buf) {
|
||||
zlib.gzip(JSON.stringify(pkg), (err, buf) => {
|
||||
expect(err).toBeNull();
|
||||
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
||||
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
||||
@ -35,7 +30,9 @@ export default function(server, express) {
|
||||
});
|
||||
});
|
||||
|
||||
express.get('/testexp_baddata', function(req, res) {
|
||||
express.get(`/${PKG_BAD_DATA}`, function(req, res) {
|
||||
expect(req).toBeDefined();
|
||||
expect(res).toBeDefined();
|
||||
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
||||
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
||||
res.send(new Buffer([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
|
||||
@ -43,24 +40,23 @@ export default function(server, express) {
|
||||
});
|
||||
|
||||
test('should not fail on bad gzip', () => {
|
||||
return server.getPackage('testexp_baddata').status(HTTP_STATUS.NOT_FOUND);
|
||||
return server.getPackage(PKG_BAD_DATA).status(HTTP_STATUS.NOT_FOUND);
|
||||
});
|
||||
|
||||
test('should understand gzipped data from uplink', () => {
|
||||
test('should understand non gzipped data from uplink', () => {
|
||||
return server.getPackage(PKG_NAME)
|
||||
.status(HTTP_STATUS.OK)
|
||||
.response(function(res) {
|
||||
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBeUndefined();
|
||||
})
|
||||
.then(function(body) {
|
||||
expect(body.name).toBe(PKG_NAME);
|
||||
expect(Object.keys(body.versions)).toHaveLength(9);
|
||||
});
|
||||
.status(HTTP_STATUS.OK)
|
||||
.response((res) => {
|
||||
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBeUndefined();
|
||||
}).then(body => {
|
||||
expect(body.name).toBe(PKG_NAME);
|
||||
expect(Object.keys(body.versions)).toHaveLength(VERSION_TOTAL);
|
||||
});
|
||||
});
|
||||
|
||||
test('should serve gzipped data', () => {
|
||||
return server.request({
|
||||
uri: '/testexp_gzip',
|
||||
uri: `/${PKG_NAME}`,
|
||||
encoding: null,
|
||||
headers: {
|
||||
[HEADER_TYPE.ACCEPT_ENCODING]: HEADERS.GZIP,
|
||||
@ -70,17 +66,21 @@ export default function(server, express) {
|
||||
.response(function(res) {
|
||||
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBe(HEADERS.GZIP);
|
||||
})
|
||||
.then(function(body) {
|
||||
.then(async function(body) {
|
||||
// should fails since is zipped
|
||||
expect(function() {
|
||||
JSON.parse(body.toString('utf8'));
|
||||
}).toThrow(/Unexpected/);
|
||||
|
||||
return new Promise(function(resolve) {
|
||||
zlib.gunzip(body, function(err, buf) {
|
||||
// we unzip content and check content
|
||||
await new Promise(function(resolve) {
|
||||
zlib.gunzip(body, function(err, buffer) {
|
||||
expect(err).toBeNull();
|
||||
body = JSON.parse(buf);
|
||||
expect(body.name).toBe(PKG_NAME);
|
||||
expect(Object.keys(body.versions)).toHaveLength(9)
|
||||
expect(buffer).not.toBeNull();
|
||||
const unzipedBody = JSON.parse(buffer);
|
||||
|
||||
expect(unzipedBody.name).toBe(PKG_NAME);
|
||||
expect(Object.keys(unzipedBody.versions)).toHaveLength(VERSION_TOTAL);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.functional';
|
||||
import {generateSha} from '../lib/test.utils';
|
||||
import {DIST_TAGS} from "../../../src/lib/utils";
|
||||
|
||||
@ -53,13 +53,8 @@ export default function(server, server2) {
|
||||
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
||||
});
|
||||
|
||||
test('scoped package on server1', () => {
|
||||
return testScopePackage(server, PORT_SERVER_1);
|
||||
});
|
||||
|
||||
test('scoped package on server2', () => {
|
||||
return testScopePackage(server2, PORT_SERVER_2);
|
||||
});
|
||||
test('scoped package on server1', () => testScopePackage(server, PORT_SERVER_1));
|
||||
test('scoped package on server2', () => testScopePackage(server2, PORT_SERVER_2));
|
||||
});
|
||||
|
||||
describe('should retrieve a scoped packages under nginx', () => {
|
||||
|
@ -1,3 +1,3 @@
|
||||
require("babel-polyfill");
|
||||
require('babel-polyfill');
|
||||
require('babel-register');
|
||||
module.exports = require('./lib/setup');
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||
|
||||
const defaultPkg = {
|
||||
'name': 'testexp-incomplete',
|
||||
@ -34,10 +34,10 @@ export default function (server, express) {
|
||||
});
|
||||
});
|
||||
|
||||
listofCalls.forEach(function (type) {
|
||||
test('should not store tarballs / ' + type, callback => {
|
||||
listofCalls.forEach((type) => {
|
||||
test(`should not store tarballs / ${type}`, callback => {
|
||||
let called;
|
||||
express.get('/testexp-incomplete/-/' + type + '.tar.gz', function (_, response) {
|
||||
express.get(`/testexp-incomplete/-/${type}.tar.gz`, function (_, response) {
|
||||
if (called) {
|
||||
return response.socket.destroy();
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {readFile} from '../lib/test.utils';
|
||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import {API_MESSAGE, HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import generatePkg from '../fixtures/package';
|
||||
import {TARBALL} from '../config.func';
|
||||
import {TARBALL} from '../config.functional';
|
||||
|
||||
const getBinary = () => readFile('../fixtures/binary');
|
||||
|
||||
@ -19,13 +19,13 @@ export default function (server, server2) {
|
||||
|
||||
pkgList.forEach(function (pkg) {
|
||||
let prefix = pkg;
|
||||
pkg = 'test-mirror-' + pkg;
|
||||
pkg = `test-mirror-${pkg}`;
|
||||
|
||||
describe(`testing mirror for ${pkg}`, () => {
|
||||
beforeAll(function () {
|
||||
return server2.putPackage(pkg, generatePkg(pkg))
|
||||
.status(HTTP_STATUS.CREATED)
|
||||
.body_ok(/created new package/);
|
||||
.body_ok(API_MESSAGE.PKG_CREATED);
|
||||
});
|
||||
|
||||
test(prefix + 'creating new package', () => {});
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {readFile} from '../lib/test.utils';
|
||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
|
||||
import generatePkg from '../fixtures/package';
|
||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||
|
||||
export default function(server, express) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {TARBALL} from '../config.func';
|
||||
import {TARBALL} from '../config.functional';
|
||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||
|
||||
|
@ -56,7 +56,7 @@ packages:
|
||||
proxy: express
|
||||
|
||||
# used by gzip.spec.js
|
||||
'testexp_gzi*':
|
||||
'testexp_gzip':
|
||||
access: $all
|
||||
publish: $all
|
||||
proxy: express
|
||||
|
@ -17,13 +17,10 @@ export default function(server) {
|
||||
|
||||
describe('should test add tag to a package', () => {
|
||||
beforeAll(function() {
|
||||
return server.putPackage(PKG_NAME, eval(
|
||||
'(' + readTags()
|
||||
.toString('utf8')
|
||||
.replace(/__NAME__/g, PKG_NAME)
|
||||
.replace(/__VERSION__/g, PKG_VERSION)
|
||||
+ ')'
|
||||
)).status(HTTP_STATUS.CREATED);
|
||||
return server.putPackage(PKG_NAME,
|
||||
JSON.parse(readTags().toString('utf8').replace(/__NAME__/g, PKG_NAME)
|
||||
.replace(/__VERSION__/g, PKG_VERSION))
|
||||
).status(HTTP_STATUS.CREATED);
|
||||
});
|
||||
|
||||
describe('should test valid formats tags', () => {
|
||||
@ -42,7 +39,7 @@ export default function(server) {
|
||||
|
||||
describe('should test handle invalid tag and version names', () => {
|
||||
const INVALID_TAG ='tag/tag/tag';
|
||||
const handleInvalidTag = function handleInvalidTag(tag, version) {
|
||||
const handleInvalidTag = function(tag, version) {
|
||||
return server.addTag(PKG_NAME, tag, version)
|
||||
.status(HTTP_STATUS.FORBIDDEN)
|
||||
.body_error(/invalid tag/);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {generateSha} from '../lib/test.utils';
|
||||
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
|
||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.functional';
|
||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||
|
||||
|
||||
@ -29,13 +29,9 @@ export default function(server, server2, server3) {
|
||||
});
|
||||
};
|
||||
|
||||
test('server1 should match with sha key from published package', () => {
|
||||
return matchTarBallSha(server);
|
||||
});
|
||||
test('server1 should match with sha key from published package', () => matchTarBallSha(server));
|
||||
test('server2 should match with sha key from published package', () => matchTarBallSha(server2));
|
||||
|
||||
test('server2 should match with sha key from published package', () => {
|
||||
return matchTarBallSha(server2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should match dist-tags', () => {
|
||||
|
@ -4,7 +4,7 @@ import assert from 'assert';
|
||||
import crypto from 'crypto';
|
||||
import {readFile} from '../lib/test.utils';
|
||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||
import {TARBALL} from '../config.func';
|
||||
import {TARBALL} from '../config.functional';
|
||||
|
||||
function getBinary() {
|
||||
return readFile('../fixtures/binary');
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* eslint comma-dangle: 0 */
|
||||
|
||||
module.exports = {
|
||||
name: 'verdaccio-func-jest',
|
||||
name: 'verdaccio-functional-jest',
|
||||
verbose: true,
|
||||
globalSetup: './functional/pre-setup.js',
|
||||
globalTeardown: './functional/teardown.js',
|
@ -6,7 +6,7 @@ import smartRequest from './request';
|
||||
import type {IServerBridge} from '../types';
|
||||
import {HEADERS, HTTP_STATUS, TOKEN_BASIC} from '../../src/lib/constants';
|
||||
import {buildToken} from "../../src/lib/utils";
|
||||
import {CREDENTIALS} from "../functional/config.func";
|
||||
import {CREDENTIALS} from "../functional/config.functional";
|
||||
|
||||
const buildAuthHeader = (user, pass): string => {
|
||||
return buildToken(TOKEN_BASIC, new Buffer(`${user}:${pass}`).toString('base64'));
|
||||
|
@ -3,7 +3,7 @@ import _ from 'lodash';
|
||||
import rimRaf from 'rimraf';
|
||||
import path from 'path';
|
||||
import {fork} from 'child_process';
|
||||
import {CREDENTIALS} from '../functional/config.func';
|
||||
import {CREDENTIALS} from '../functional/config.functional';
|
||||
import {HTTP_STATUS} from '../../src/lib/constants';
|
||||
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types';
|
||||
|
||||
|
@ -10,6 +10,7 @@ import {setup} from '../../../src/lib/logger';
|
||||
|
||||
import type {Config} from '@verdaccio/types';
|
||||
import type {IStorageHandler} from '../../../types/index';
|
||||
import {API_ERROR} from '../../../src/lib/constants';
|
||||
|
||||
setup(configExample.logs);
|
||||
|
||||
@ -75,7 +76,7 @@ describe('StorageTest', () => {
|
||||
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
||||
expect(errors).toBeInstanceOf(Array);
|
||||
expect(errors[0][0].statusCode).toBe(404);
|
||||
expect(errors[0][0].message).toMatch(/package doesn't exist on uplink/);
|
||||
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -8,7 +8,7 @@ import {setup} from '../../../src/lib/logger';
|
||||
|
||||
import type {Config, UpLinkConf} from '@verdaccio/types';
|
||||
import type {IProxy} from '../../../types/index';
|
||||
import {DEFAULT_REGISTRY} from "../../../src/lib/constants";
|
||||
import {API_ERROR, DEFAULT_REGISTRY} from "../../../src/lib/constants";
|
||||
|
||||
setup([]);
|
||||
|
||||
@ -59,7 +59,7 @@ describe('UpStorge', () => {
|
||||
proxy.getRemoteMetadata('@verdaccio/fake-package', {etag: '123456'}, (err) => {
|
||||
expect(err).not.toBeNull();
|
||||
expect(err.statusCode).toBe(404);
|
||||
expect(err.message).toMatch(/package doesn't exist on uplink/);
|
||||
expect(err.message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user