diff --git a/.npmignore b/.npmignore index 41a76f1bf..2bad67b1d 100644 --- a/.npmignore +++ b/.npmignore @@ -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 diff --git a/package.json b/package.json index 468dea8ce..108e4f3b3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/auth.js b/src/lib/auth.js index ae3d37929..377c3f41d 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -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}`)); } }; }; diff --git a/src/lib/constants.js b/src/lib/constants.js index a7172f17d..2e8a3c71b 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -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', diff --git a/src/lib/utils.js b/src/lib/utils.js index a16823fd7..5c87cd2f1 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -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 { diff --git a/test/e2e/pre-setup.js b/test/e2e/pre-setup.js index c5842283f..f14d07201 100644 --- a/test/e2e/pre-setup.js +++ b/test/e2e/pre-setup.js @@ -1,3 +1,3 @@ -require("babel-polyfill"); +require('babel-polyfill'); require('babel-register'); module.exports = require('./setup'); diff --git a/test/functional/basic/basic.js b/test/functional/basic/basic.js index 969f14d62..b96c0db66 100644 --- a/test/functional/basic/basic.js +++ b/test/functional/basic/basic.js @@ -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) diff --git a/test/functional/basic/whoIam.js b/test/functional/basic/whoIam.js index 6910b66e3..2798d8d92 100644 --- a/test/functional/basic/whoIam.js +++ b/test/functional/basic/whoIam.js @@ -1,4 +1,4 @@ -import {CREDENTIALS} from "../config.func"; +import {CREDENTIALS} from "../config.functional"; module.exports = function(server) { diff --git a/test/functional/config.func.js b/test/functional/config.functional.js similarity index 100% rename from test/functional/config.func.js rename to test/functional/config.functional.js diff --git a/test/functional/fixtures/package.js b/test/functional/fixtures/package.js index f31662540..febe57ba1 100644 --- a/test/functional/fixtures/package.js +++ b/test/functional/fixtures/package.js @@ -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') { diff --git a/test/functional/fixtures/publish.json b/test/functional/fixtures/publish.json new file mode 100644 index 000000000..c1e70840b --- /dev/null +++ b/test/functional/fixtures/publish.json @@ -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 } } } diff --git a/test/functional/fixtures/publish.json5 b/test/functional/fixtures/publish.json5 index 2323a2956..9f15383d1 100644 --- a/test/functional/fixtures/publish.json5 +++ b/test/functional/fixtures/publish.json5 @@ -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 } } } diff --git a/test/functional/lib/environment.js b/test/functional/lib/environment.js index 0dc3dd4e6..a2872df60 100644 --- a/test/functional/lib/environment.js +++ b/test/functional/lib/environment.js @@ -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; diff --git a/test/functional/lib/simple_server.js b/test/functional/lib/simple_server.js index 3ffb8e34a..86bbcbfb0 100644 --- a/test/functional/lib/simple_server.js +++ b/test/functional/lib/simple_server.js @@ -8,7 +8,6 @@ export default class ExpressServer { constructor() { this.app = express(); - this.server; } start(port: number): Promise { diff --git a/test/functional/notifications/notify.js b/test/functional/notifications/notify.js index c4094c5fb..17b47aa58 100644 --- a/test/functional/notifications/notify.js +++ b/test/functional/notifications/notify.js @@ -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) { diff --git a/test/functional/package/access.js b/test/functional/package/access.js index 0363de9a0..4f7db25f1 100644 --- a/test/functional/package/access.js +++ b/test/functional/package/access.js @@ -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); } } ); diff --git a/test/functional/package/gzip.js b/test/functional/package/gzip.js index d647a9dd0..996b6d9f3 100644 --- a/test/functional/package/gzip.js +++ b/test/functional/package/gzip.js @@ -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(); }); }); diff --git a/test/functional/package/scoped.js b/test/functional/package/scoped.js index e1361f98d..52bdbb0d8 100644 --- a/test/functional/package/scoped.js +++ b/test/functional/package/scoped.js @@ -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', () => { diff --git a/test/functional/pre-setup.js b/test/functional/pre-setup.js index 98aa3432c..faf887e90 100644 --- a/test/functional/pre-setup.js +++ b/test/functional/pre-setup.js @@ -1,3 +1,3 @@ -require("babel-polyfill"); +require('babel-polyfill'); require('babel-register'); module.exports = require('./lib/setup'); diff --git a/test/functional/sanity/incomplete.js b/test/functional/sanity/incomplete.js index 5eceb09fb..a320a6206 100644 --- a/test/functional/sanity/incomplete.js +++ b/test/functional/sanity/incomplete.js @@ -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(); } diff --git a/test/functional/sanity/mirror.js b/test/functional/sanity/mirror.js index 549cba05b..69b18364e 100644 --- a/test/functional/sanity/mirror.js +++ b/test/functional/sanity/mirror.js @@ -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', () => {}); diff --git a/test/functional/sanity/nullstorage.js b/test/functional/sanity/nullstorage.js index 917a693cb..e4c13a915 100644 --- a/test/functional/sanity/nullstorage.js +++ b/test/functional/sanity/nullstorage.js @@ -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'; diff --git a/test/functional/sanity/racycrash.js b/test/functional/sanity/racycrash.js index 88db2aec5..28bdd9c0c 100644 --- a/test/functional/sanity/racycrash.js +++ b/test/functional/sanity/racycrash.js @@ -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) { diff --git a/test/functional/scenarios/gh29.js b/test/functional/scenarios/gh29.js index a7d610315..03262ad2d 100644 --- a/test/functional/scenarios/gh29.js +++ b/test/functional/scenarios/gh29.js @@ -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"; diff --git a/test/functional/store/config-1.yaml b/test/functional/store/config-1.yaml index 94814b81b..a6aa84633 100644 --- a/test/functional/store/config-1.yaml +++ b/test/functional/store/config-1.yaml @@ -56,7 +56,7 @@ packages: proxy: express # used by gzip.spec.js - 'testexp_gzi*': + 'testexp_gzip': access: $all publish: $all proxy: express diff --git a/test/functional/tags/addtag.js b/test/functional/tags/addtag.js index 539f503e7..951ccee0f 100644 --- a/test/functional/tags/addtag.js +++ b/test/functional/tags/addtag.js @@ -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/); diff --git a/test/functional/tags/dist-tags-merge.js b/test/functional/tags/dist-tags-merge.js index c8ee14b7f..8ce5f8fa4 100644 --- a/test/functional/tags/dist-tags-merge.js +++ b/test/functional/tags/dist-tags-merge.js @@ -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', () => { diff --git a/test/functional/uplinks/cache.js b/test/functional/uplinks/cache.js index d156c9f7d..40600e060 100644 --- a/test/functional/uplinks/cache.js +++ b/test/functional/uplinks/cache.js @@ -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'); diff --git a/test/jest.config.func.js b/test/jest.config.functional.js similarity index 86% rename from test/jest.config.func.js rename to test/jest.config.functional.js index 723c3a5c3..2912b05a1 100644 --- a/test/jest.config.func.js +++ b/test/jest.config.functional.js @@ -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', diff --git a/test/lib/server.js b/test/lib/server.js index 6243172f0..c74b26561 100644 --- a/test/lib/server.js +++ b/test/lib/server.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')); diff --git a/test/lib/server_process.js b/test/lib/server_process.js index ae895e4b4..8eb551c94 100644 --- a/test/lib/server_process.js +++ b/test/lib/server_process.js @@ -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'; diff --git a/test/unit/api/store.spec.js b/test/unit/api/store.spec.js index b2ff2afca..03566c852 100644 --- a/test/unit/api/store.spec.js +++ b/test/unit/api/store.spec.js @@ -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(); }); }); diff --git a/test/unit/api/up-storage.spec.js b/test/unit/api/up-storage.spec.js index dcff97382..0cf58f614 100644 --- a/test/unit/api/up-storage.spec.js +++ b/test/unit/api/up-storage.spec.js @@ -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(); }); });