mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-06 22:40:26 -05:00
refactor: functional testing add more test
This commit is contained in:
parent
037095f851
commit
4cbbb2f370
7 changed files with 63 additions and 134 deletions
|
@ -2,14 +2,17 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import {VerdaccioConfig} from './lib/verdaccio-server';
|
import {VerdaccioConfig} from './lib/verdaccio-server';
|
||||||
import Server from './lib/server';
|
|
||||||
import VerdaccioProcess from './lib/server_process';
|
import VerdaccioProcess from './lib/server_process';
|
||||||
import packageAccess from './package/access';
|
import ExpressServer from './lib/simple_server';
|
||||||
|
import Server from './lib/server';
|
||||||
import type {IServerProcess, IServerBridge} from './lib/types';
|
import type {IServerProcess, IServerBridge} from './lib/types';
|
||||||
|
|
||||||
describe('functional test verdaccio', function() {
|
import packageAccess from './package/access.spec';
|
||||||
|
import packageGzip from './package/gzip.spec';
|
||||||
|
import packageScoped from './package/scoped.spec';
|
||||||
|
|
||||||
const servers: IServerBridge[] = [];
|
describe('functional test verdaccio', function() {
|
||||||
|
const EXPRESS_PORT = 55550;
|
||||||
const processRunning = [];
|
const processRunning = [];
|
||||||
const config1 = new VerdaccioConfig(
|
const config1 = new VerdaccioConfig(
|
||||||
'./store/test-storage',
|
'./store/test-storage',
|
||||||
|
@ -29,7 +32,7 @@ describe('functional test verdaccio', function() {
|
||||||
const process1: IServerProcess = new VerdaccioProcess(config1, server1);
|
const process1: IServerProcess = new VerdaccioProcess(config1, server1);
|
||||||
const process2: IServerProcess = new VerdaccioProcess(config2, server2);
|
const process2: IServerProcess = new VerdaccioProcess(config2, server2);
|
||||||
const process3: IServerProcess = new VerdaccioProcess(config3, server3);
|
const process3: IServerProcess = new VerdaccioProcess(config3, server3);
|
||||||
servers.push(server1, server1, server1);
|
const express: any = new ExpressServer();
|
||||||
|
|
||||||
beforeAll((done) => {
|
beforeAll((done) => {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
@ -39,7 +42,11 @@ describe('functional test verdaccio', function() {
|
||||||
_.map(forks, (fork) => {
|
_.map(forks, (fork) => {
|
||||||
processRunning.push(fork[0]);
|
processRunning.push(fork[0]);
|
||||||
});
|
});
|
||||||
done();
|
express.start(EXPRESS_PORT).then((app) =>{
|
||||||
|
done();
|
||||||
|
}, (err) => {
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
done(error);
|
done(error);
|
||||||
});
|
});
|
||||||
|
@ -49,9 +56,12 @@ describe('functional test verdaccio', function() {
|
||||||
_.map(processRunning, (fork) => {
|
_.map(processRunning, (fork) => {
|
||||||
fork.stop();
|
fork.stop();
|
||||||
});
|
});
|
||||||
|
express.server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
packageAccess(server1);
|
packageAccess(server1);
|
||||||
|
packageGzip(server1, express.app);
|
||||||
|
packageScoped(server1, server2);
|
||||||
|
|
||||||
test('process test', () => {
|
test('process test', () => {
|
||||||
expect(true).toBeTruthy();
|
expect(true).toBeTruthy();
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// require('./lib/startup');
|
|
||||||
//import _ from 'lodash';
|
|
||||||
|
|
||||||
import {VerdaccioServer, VerdaccioConfig} from './lib/verdaccio-server';
|
|
||||||
|
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
describe('functional test verdaccio', function() {
|
|
||||||
|
|
||||||
const config1 = new VerdaccioConfig('./store/test-storage', '/store/config-1.yaml', 'http://localhost:55551/');
|
|
||||||
const config2 = new VerdaccioConfig('./store/test-storage2', '/store/config-2.yaml', 'http://localhost:55552/');
|
|
||||||
const config3 = new VerdaccioConfig('./store/test-storage3', '/store/config-3.yaml', 'http://localhost:55553/');
|
|
||||||
const server1 = new VerdaccioServer(config1);
|
|
||||||
const server2 = new VerdaccioServer(config2);
|
|
||||||
const server3 = new VerdaccioServer(config3);
|
|
||||||
|
|
||||||
before(function(done) {
|
|
||||||
Promise.all([
|
|
||||||
server1.start(),
|
|
||||||
server2.start(),
|
|
||||||
server3.start(),
|
|
||||||
]).then(() => {
|
|
||||||
done();
|
|
||||||
}).catch(function(error) {
|
|
||||||
console.error("error on start servers", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('authenticate', function() {
|
|
||||||
/* test for before() */
|
|
||||||
});
|
|
||||||
|
|
||||||
require('./package/access')();
|
|
||||||
// require('./basic')();
|
|
||||||
// require('./gh29')();
|
|
||||||
// require('./tags/tags')();
|
|
||||||
// require('./package/gzip.spec')();
|
|
||||||
// require('./sanity/incomplete')();
|
|
||||||
// require('./sanity/mirror')();
|
|
||||||
// require('./tags/preserve_tags.spec')();
|
|
||||||
// require('./readme/readme.spec')();
|
|
||||||
// require('./sanity/nullstorage')();
|
|
||||||
// require('./performance/race')();
|
|
||||||
// require('./sanity/racycrash')();
|
|
||||||
// require('./package/scoped.spec')();
|
|
||||||
// require('./sanity/security')();
|
|
||||||
// require('./adduser/adduser')();
|
|
||||||
// require('./adduser/logout')();
|
|
||||||
// require('./tags/addtag.spec')();
|
|
||||||
// require('./plugins/auth.spec')();
|
|
||||||
// require('./notifications/notify')();
|
|
||||||
// // // requires packages published to server1/server2
|
|
||||||
// require('./uplink.cache.spec')();
|
|
||||||
// require('./uplink.auth.spec')();
|
|
||||||
|
|
||||||
after(function(done) {
|
|
||||||
const check = (server) => {
|
|
||||||
return server.stop();
|
|
||||||
};
|
|
||||||
|
|
||||||
Promise.all([check(server1), check(server2), check(server3)]).then(function() {
|
|
||||||
done();
|
|
||||||
}, (reason) => {
|
|
||||||
assert.equal(reason, null);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
process.on('unhandledRejection', function(err) {
|
|
||||||
process.nextTick(function() {
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -2,17 +2,23 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
|
|
||||||
export class ExpressServer {
|
export default class ExpressServer {
|
||||||
static start(): Promise<any> {
|
app: any;
|
||||||
return new Promise(function(resolve, reject) {
|
server: any;
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.use(bodyParser.json());
|
constructor() {
|
||||||
app.use(bodyParser.urlencoded({
|
this.app = express();
|
||||||
|
this.server;
|
||||||
|
}
|
||||||
|
|
||||||
|
start(port: number): Promise<any> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.app.use(bodyParser.json());
|
||||||
|
this.app.use(bodyParser.urlencoded({
|
||||||
extended: true
|
extended: true
|
||||||
}));
|
}));
|
||||||
|
|
||||||
app.listen(55550, function starExpressServer() {
|
this.server = this.app.listen(port, function starExpressServer() {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
|
|
||||||
const crypto = require('crypto');
|
import crypto from 'crypto';
|
||||||
const fs = require('fs');
|
import fs from 'fs';
|
||||||
const path = require('path');
|
import path from 'path';
|
||||||
|
|
||||||
exports.generateSha = function generateSha(key) {
|
function generateSha(key) {
|
||||||
return crypto.createHash('sha1', 'binary').update(key).digest('hex');
|
return crypto.createHash('sha1', 'binary').update(key).digest('hex');
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function readFile(filePath) {
|
||||||
exports.readFile = function readFile(filePath) {
|
|
||||||
return fs.readFileSync(path.join(__dirname, `/${filePath}`));
|
return fs.readFileSync(path.join(__dirname, `/${filePath}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { generateSha, readFile }
|
||||||
|
|
|
@ -1,20 +1,14 @@
|
||||||
'use strict';
|
import assert from 'assert';
|
||||||
|
import zlib from 'zlib';
|
||||||
|
import {readFile} from '../lib/test.utils';
|
||||||
|
|
||||||
require('../lib/startup');
|
export default function(server, express) {
|
||||||
|
|
||||||
const assert = require('assert');
|
describe('test gzip support', () => {
|
||||||
const zlib = require('zlib');
|
beforeAll(function() {
|
||||||
const utils = require('../lib/test.utils');
|
|
||||||
|
|
||||||
module.exports = function() {
|
|
||||||
let server = process.server;
|
|
||||||
let express = process.express;
|
|
||||||
|
|
||||||
describe('test gzip support', function() {
|
|
||||||
before(function() {
|
|
||||||
express.get('/testexp_gzip', function(req, res) {
|
express.get('/testexp_gzip', function(req, res) {
|
||||||
const pkg = eval(
|
const pkg = eval(
|
||||||
'(' + utils.readFile('../fixtures/publish.json5')
|
'(' + readFile('../fixtures/publish.json5')
|
||||||
.toString('utf8')
|
.toString('utf8')
|
||||||
.replace(/__NAME__/g, 'testexp_gzip')
|
.replace(/__NAME__/g, 'testexp_gzip')
|
||||||
.replace(/__VERSION__/g, '0.0.1')
|
.replace(/__VERSION__/g, '0.0.1')
|
||||||
|
@ -46,11 +40,11 @@ module.exports = function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not fail on bad gzip', function() {
|
test('should not fail on bad gzip', () => {
|
||||||
return server.getPackage('testexp_baddata').status(404);
|
return server.getPackage('testexp_baddata').status(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should understand gzipped data from uplink', function() {
|
test('should understand gzipped data from uplink', () => {
|
||||||
return server.getPackage('testexp_gzip')
|
return server.getPackage('testexp_gzip')
|
||||||
.status(200)
|
.status(200)
|
||||||
.response(function(res) {
|
.response(function(res) {
|
||||||
|
@ -62,7 +56,7 @@ module.exports = function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should serve gzipped data', function() {
|
test('should serve gzipped data', () => {
|
||||||
return server.request({
|
return server.request({
|
||||||
uri: '/testexp_gzip',
|
uri: '/testexp_gzip',
|
||||||
encoding: null,
|
encoding: null,
|
||||||
|
@ -91,5 +85,4 @@ module.exports = function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const assert = require('assert');
|
import assert from 'assert';
|
||||||
const utils = require ('../lib/test.utils');
|
import {generateSha} from '../lib/test.utils';
|
||||||
|
|
||||||
module.exports = function() {
|
export default function(server, server2) {
|
||||||
const server = process.server;
|
|
||||||
const server2 = process.server2;
|
|
||||||
|
|
||||||
describe('test-scoped', function() {
|
describe('test-scoped', () => {
|
||||||
before(function() {
|
beforeAll(function() {
|
||||||
return server.request({
|
return server.request({
|
||||||
uri: '/@test%2fscoped',
|
uri: '/@test%2fscoped',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -19,7 +16,7 @@ module.exports = function() {
|
||||||
}).status(201);
|
}).status(201);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should publish scope package', function() {});
|
test('should publish scope package', () => {});
|
||||||
|
|
||||||
describe('should get scoped packages tarball', () => {
|
describe('should get scoped packages tarball', () => {
|
||||||
const uploadScopedTarBall = (server) => {
|
const uploadScopedTarBall = (server) => {
|
||||||
|
@ -27,22 +24,22 @@ module.exports = function() {
|
||||||
.status(200)
|
.status(200)
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
// not real sha due to utf8 conversion
|
// not real sha due to utf8 conversion
|
||||||
assert.strictEqual(utils.generateSha(body),
|
assert.strictEqual(generateSha(body),
|
||||||
'6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
'6e67b14e2c0e450b942e2bc8086b49e90f594790');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should be a scoped tarball from server1', () => {
|
test('should be a scoped tarball from server1', () => {
|
||||||
return uploadScopedTarBall(server);
|
return uploadScopedTarBall(server);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be a scoped tarball from server2', () => {
|
test('should be a scoped tarball from server2', () => {
|
||||||
return uploadScopedTarBall(server2);
|
return uploadScopedTarBall(server2);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should retrieve scoped packages', function() {
|
describe('should retrieve scoped packages', () => {
|
||||||
const testScopePackage = (server, port) => server.getPackage('@test/scoped')
|
const testScopePackage = (server, port) => server.getPackage('@test/scoped')
|
||||||
.status(200)
|
.status(200)
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
|
@ -53,17 +50,17 @@ module.exports = function() {
|
||||||
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'});
|
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scoped package on server1', () => {
|
test('scoped package on server1', () => {
|
||||||
return testScopePackage(server, '55551');
|
return testScopePackage(server, '55551');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scoped package on server2', () => {
|
test('scoped package on server2', () => {
|
||||||
return testScopePackage(server2, '55552');
|
return testScopePackage(server2, '55552');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should retrieve a scoped packages under nginx', function() {
|
describe('should retrieve a scoped packages under nginx', () => {
|
||||||
it('should work nginx workaround', () => {
|
test('should work nginx workaround', () => {
|
||||||
return server2.request({
|
return server2.request({
|
||||||
uri: '/@test/scoped/1.0.0'
|
uri: '/@test/scoped/1.0.0'
|
||||||
}).status(200)
|
}).status(200)
|
||||||
|
@ -75,4 +72,4 @@ module.exports = function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
Loading…
Reference in a new issue