0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/test/functional/lib/environment.ts
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

95 lines
2.8 KiB
TypeScript

import { yellow, green, blue, magenta } from 'kleur';
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 {IServerBridge} from '../../types';
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.functional';
const EXPRESS_PORT = 55550;
class FunctionalEnvironment extends NodeEnvironment {
public config: any;
public constructor(config: any) {
super(config)
}
public async startWeb() {
const express: any = new ExpressServer();
return await express.start(EXPRESS_PORT);
}
public async setup() {
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
// @ts-ignore
const DEBUG_INJECT: boolean = process.env.VERDACCIO_DEBUG_INJECT ? process.env.VERDACCIO_DEBUG_INJECT : false;
const forkList = [];
const serverList = [];
const pathStore = path.join(__dirname, '../store');
const listServers = [
{
port: PORT_SERVER_1,
config: '/config-1.yaml',
storage: '/test-storage'
},
{
port: PORT_SERVER_2,
config: '/config-2.yaml',
storage: '/test-storage2'
},
{
port: PORT_SERVER_3,
config: '/config-3.yaml',
storage: '/test-storage3'
}
];
console.log(green('Setup Verdaccio Servers'));
const app = await this.startWeb();
this.global.__WEB_SERVER__ = app;
for (let config of listServers) {
const verdaccioConfig = new VerdaccioConfig(
path.join(pathStore, config.storage),
path.join(pathStore, config.config),
`http://${DOMAIN_SERVERS}:${config.port}/`, config.port);
console.log(magenta(`Running registry ${config.config} on port ${config.port}`));
const server: IServerBridge = new Server(verdaccioConfig.domainPath);
serverList.push(server);
const process = new VerdaccioProcess(verdaccioConfig, server, SILENCE_LOG, DEBUG_INJECT);
const fork = await process.init();
console.log(blue(`Fork PID ${fork[1]}`));
forkList.push(fork);
}
this.global.__SERVERS_PROCESS__ = forkList;
this.global.__SERVERS__ = serverList;
}
public async teardown() {
await super.teardown();
console.log(yellow('Teardown Test Environment.'));
if (!this.global.__SERVERS_PROCESS__) {
throw new Error("There are no servers to stop");
}
// shutdown verdaccio
for (let server of this.global.__SERVERS_PROCESS__) {
server[0].stop();
}
// close web server
this.global.__WEB_SERVER__.server.close();
}
public runScript(script: string) {
return super.runScript(script);
}
}
module.exports = FunctionalEnvironment;