1
1
import path from 'path' ;
2
2
3
- import chalk from 'chalk ' ;
3
+ import { yellow , green , blue , magenta } from 'kleur ' ;
4
4
import NodeEnvironment from 'jest-environment-node' ;
5
5
6
6
import { VerdaccioConfig } from '../../lib/verdaccio-server' ;
@@ -28,17 +28,17 @@ class FunctionalEnvironment extends NodeEnvironment {
28
28
const SILENCE_LOG = ! process . env . VERDACCIO_DEBUG ;
29
29
// @ts -ignore
30
30
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 [ ] = [ ] ;
33
33
const pathStore = path . join ( __dirname , '../store' ) ;
34
34
const listServers = [
35
35
{
36
36
port : PORT_SERVER_1 ,
37
37
config : '/config-1.yaml' ,
38
38
storage : '/test-storage1' ,
39
- } ,
39
+ }
40
40
] ;
41
- console . log ( chalk . green ( 'Setup Verdaccio Servers' ) ) ;
41
+ console . log ( green ( 'Setup Verdaccio Servers' ) ) ;
42
42
43
43
const app = await this . startWeb ( ) ;
44
44
this . global . __GITLAB_SERVER__ = app ;
@@ -47,16 +47,14 @@ class FunctionalEnvironment extends NodeEnvironment {
47
47
const verdaccioConfig = new VerdaccioConfig (
48
48
path . join ( pathStore , config . storage ) ,
49
49
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 } ` ) ) ;
54
52
const server : IServerBridge = new Server ( verdaccioConfig . domainPath ) ;
55
53
serverList . push ( server ) ;
56
54
const process = new VerdaccioProcess ( verdaccioConfig , server , SILENCE_LOG , DEBUG_INJECT ) ;
57
55
58
56
const fork = await process . init ( ) ;
59
- console . log ( chalk . blue ( `Fork PID ${ fork [ 1 ] } ` ) ) ;
57
+ console . log ( blue ( `Fork PID ${ fork [ 1 ] } ` ) ) ;
60
58
forkList . push ( fork ) ;
61
59
}
62
60
@@ -66,7 +64,12 @@ class FunctionalEnvironment extends NodeEnvironment {
66
64
67
65
public async teardown ( ) {
68
66
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
+
70
73
// shutdown verdaccio
71
74
for ( const server of this . global . __SERVERS_PROCESS__ ) {
72
75
server [ 0 ] . stop ( ) ;
0 commit comments