0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

refactor: functional testing add more test

This commit is contained in:
Juan Picado @jotadeveloper 2017-12-02 09:52:40 +01:00 committed by juanpicado
parent 037095f851
commit 4cbbb2f370
7 changed files with 63 additions and 134 deletions

View file

@ -2,14 +2,17 @@
import _ from 'lodash';
import {VerdaccioConfig} from './lib/verdaccio-server';
import Server from './lib/server';
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';
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 config1 = new VerdaccioConfig(
'./store/test-storage',
@ -29,7 +32,7 @@ describe('functional test verdaccio', function() {
const process1: IServerProcess = new VerdaccioProcess(config1, server1);
const process2: IServerProcess = new VerdaccioProcess(config2, server2);
const process3: IServerProcess = new VerdaccioProcess(config3, server3);
servers.push(server1, server1, server1);
const express: any = new ExpressServer();
beforeAll((done) => {
Promise.all([
@ -39,7 +42,11 @@ describe('functional test verdaccio', function() {
_.map(forks, (fork) => {
processRunning.push(fork[0]);
});
express.start(EXPRESS_PORT).then((app) =>{
done();
}, (err) => {
done(err);
});
}).catch((error) => {
done(error);
});
@ -49,9 +56,12 @@ describe('functional test verdaccio', function() {
_.map(processRunning, (fork) => {
fork.stop();
});
express.server.close();
});
packageAccess(server1);
packageGzip(server1, express.app);
packageScoped(server1, server2);
test('process test', () => {
expect(true).toBeTruthy();

View file

@ -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;
});
});

View file

@ -2,17 +2,23 @@
import express from 'express';
import bodyParser from 'body-parser';
export class ExpressServer {
static start(): Promise<any> {
return new Promise(function(resolve, reject) {
const app = express();
export default class ExpressServer {
app: any;
server: any;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
constructor() {
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
}));
app.listen(55550, function starExpressServer() {
this.server = this.app.listen(port, function starExpressServer() {
resolve();
});
});

View file

@ -1,13 +1,14 @@
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
exports.generateSha = function generateSha(key) {
function generateSha(key) {
return crypto.createHash('sha1', 'binary').update(key).digest('hex');
};
}
exports.readFile = function readFile(filePath) {
function readFile(filePath) {
return fs.readFileSync(path.join(__dirname, `/${filePath}`));
}
export { generateSha, readFile }

View file

@ -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');
const zlib = require('zlib');
const utils = require('../lib/test.utils');
module.exports = function() {
let server = process.server;
let express = process.express;
describe('test gzip support', function() {
before(function() {
describe('test gzip support', () => {
beforeAll(function() {
express.get('/testexp_gzip', function(req, res) {
const pkg = eval(
'(' + utils.readFile('../fixtures/publish.json5')
'(' + readFile('../fixtures/publish.json5')
.toString('utf8')
.replace(/__NAME__/g, 'testexp_gzip')
.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);
});
it('should understand gzipped data from uplink', function() {
test('should understand gzipped data from uplink', () => {
return server.getPackage('testexp_gzip')
.status(200)
.response(function(res) {
@ -62,7 +56,7 @@ module.exports = function() {
});
});
it('should serve gzipped data', function() {
test('should serve gzipped data', () => {
return server.request({
uri: '/testexp_gzip',
encoding: null,
@ -91,5 +85,4 @@ module.exports = function() {
});
});
});
};
}

View file

@ -1,14 +1,11 @@
'use strict';
const assert = require('assert');
const utils = require ('../lib/test.utils');
import assert from 'assert';
import {generateSha} from '../lib/test.utils';
module.exports = function() {
const server = process.server;
const server2 = process.server2;
export default function(server, server2) {
describe('test-scoped', function() {
before(function() {
describe('test-scoped', () => {
beforeAll(function() {
return server.request({
uri: '/@test%2fscoped',
headers: {
@ -19,7 +16,7 @@ module.exports = function() {
}).status(201);
});
it('should publish scope package', function() {});
test('should publish scope package', () => {});
describe('should get scoped packages tarball', () => {
const uploadScopedTarBall = (server) => {
@ -27,22 +24,22 @@ module.exports = function() {
.status(200)
.then(function(body) {
// not real sha due to utf8 conversion
assert.strictEqual(utils.generateSha(body),
assert.strictEqual(generateSha(body),
'6e67b14e2c0e450b942e2bc8086b49e90f594790');
});
};
it('should be a scoped tarball from server1', () => {
test('should be a scoped tarball from server1', () => {
return uploadScopedTarBall(server);
});
it('should be a scoped tarball from server2', () => {
test('should be a scoped tarball from server2', () => {
return uploadScopedTarBall(server2);
});
});
describe('should retrieve scoped packages', function() {
describe('should retrieve scoped packages', () => {
const testScopePackage = (server, port) => server.getPackage('@test/scoped')
.status(200)
.then(function(body) {
@ -53,17 +50,17 @@ module.exports = function() {
assert.deepEqual(body['dist-tags'], {latest: '1.0.0'});
});
it('scoped package on server1', () => {
test('scoped package on server1', () => {
return testScopePackage(server, '55551');
});
it('scoped package on server2', () => {
test('scoped package on server2', () => {
return testScopePackage(server2, '55552');
});
});
describe('should retrieve a scoped packages under nginx', function() {
it('should work nginx workaround', () => {
describe('should retrieve a scoped packages under nginx', () => {
test('should work nginx workaround', () => {
return server2.request({
uri: '/@test/scoped/1.0.0'
}).status(200)
@ -75,4 +72,4 @@ module.exports = function() {
});
});
});
};
}