11import path from 'path' ;
22
3- import chalk from 'chalk ' ;
3+ import { yellow , green , blue , magenta } from 'kleur ' ;
44import NodeEnvironment from 'jest-environment-node' ;
55
66import { VerdaccioConfig } from '../../lib/verdaccio-server' ;
@@ -28,17 +28,17 @@ class FunctionalEnvironment extends NodeEnvironment {
2828 const SILENCE_LOG = ! process . env . VERDACCIO_DEBUG ;
2929 // @ts -ignore
3030 const DEBUG_INJECT : boolean = process . env . VERDACCIO_DEBUG_INJECT ? process . env . VERDACCIO_DEBUG_INJECT : false ;
31- const forkList = [ ] ;
32- const serverList = [ ] ;
31+ const forkList : any [ ] = [ ] ;
32+ const serverList : IServerBridge [ ] = [ ] ;
3333 const pathStore = path . join ( __dirname , '../store' ) ;
3434 const listServers = [
3535 {
3636 port : PORT_SERVER_1 ,
3737 config : '/config-1.yaml' ,
3838 storage : '/test-storage1' ,
39- } ,
39+ }
4040 ] ;
41- console . log ( chalk . green ( 'Setup Verdaccio Servers' ) ) ;
41+ console . log ( green ( 'Setup Verdaccio Servers' ) ) ;
4242
4343 const app = await this . startWeb ( ) ;
4444 this . global . __GITLAB_SERVER__ = app ;
@@ -47,16 +47,14 @@ class FunctionalEnvironment extends NodeEnvironment {
4747 const verdaccioConfig = new VerdaccioConfig (
4848 path . join ( pathStore , config . storage ) ,
4949 path . join ( pathStore , config . config ) ,
50- `http://${ DOMAIN_SERVERS } :${ config . port } /` ,
51- config . port
52- ) ;
53- console . log ( chalk . magentaBright ( `Running registry ${ config . config } on port ${ config . port } ` ) ) ;
50+ `http://${ DOMAIN_SERVERS } :${ config . port } /` , config . port ) ;
51+ console . log ( magenta ( `Running registry ${ config . config } on port ${ config . port } ` ) ) ;
5452 const server : IServerBridge = new Server ( verdaccioConfig . domainPath ) ;
5553 serverList . push ( server ) ;
5654 const process = new VerdaccioProcess ( verdaccioConfig , server , SILENCE_LOG , DEBUG_INJECT ) ;
5755
5856 const fork = await process . init ( ) ;
59- console . log ( chalk . blue ( `Fork PID ${ fork [ 1 ] } ` ) ) ;
57+ console . log ( blue ( `Fork PID ${ fork [ 1 ] } ` ) ) ;
6058 forkList . push ( fork ) ;
6159 }
6260
@@ -66,7 +64,12 @@ class FunctionalEnvironment extends NodeEnvironment {
6664
6765 public async teardown ( ) {
6866 await super . teardown ( ) ;
69- console . log ( chalk . yellow ( 'Teardown Test Environment.' ) ) ;
67+ console . log ( yellow ( 'Teardown Test Environment.' ) ) ;
68+
69+ if ( ! this . global . __SERVERS_PROCESS__ ) {
70+ throw new Error ( "There are no servers to stop" ) ;
71+ }
72+
7073 // shutdown verdaccio
7174 for ( const server of this . global . __SERVERS_PROCESS__ ) {
7275 server [ 0 ] . stop ( ) ;
0 commit comments