1
1
import path from "path" ;
2
- import test , { Test } from "tape-promise/tape" ;
3
2
import { v4 as uuidv4 } from "uuid" ;
4
-
3
+ import "jest-extended" ;
5
4
import { LogLevelDesc } from "@hyperledger/cactus-common" ;
6
-
7
5
import {
8
6
ApiServer ,
9
7
AuthorizationProtocol ,
@@ -14,48 +12,68 @@ import {
14
12
PluginImportType ,
15
13
} from "@hyperledger/cactus-core-api" ;
16
14
15
+ //const nodeCleanup = require("node-cleanup");
17
16
const logLevel : LogLevelDesc = "TRACE" ;
17
+ const testCase = "can import plugins at runtime (CLI)" ;
18
+ describe ( testCase , ( ) => {
19
+ let apiServer : ApiServer ;
18
20
19
- test ( "can import plugins at runtime (CLI)" , async ( t : Test ) => {
20
- const pluginsPath = path . join (
21
- __dirname , // start at the current file's path
22
- "../../../../../../" , // walk back up to the project root
23
- ".tmp/test/cmd-api-server/runtime-plugin-imports_test" , // the dir path from the root
24
- uuidv4 ( ) , // then a random directory to ensure proper isolation
25
- ) ;
26
- const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
21
+ afterEach ( ( ) => {
22
+ jest . useRealTimers ( ) ;
23
+ } ) ;
27
24
28
- const configService = new ConfigService ( ) ;
29
- const apiServerOptions = await configService . newExampleConfig ( ) ;
30
- apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
31
- apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
32
- apiServerOptions . configFile = "" ;
33
- apiServerOptions . apiCorsDomainCsv = "*" ;
34
- apiServerOptions . apiPort = 0 ;
35
- apiServerOptions . cockpitPort = 0 ;
36
- apiServerOptions . grpcPort = 0 ;
37
- apiServerOptions . apiTlsEnabled = false ;
38
- apiServerOptions . plugins = [
39
- {
40
- packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
41
- type : PluginImportType . Local ,
42
- action : PluginImportAction . Install ,
43
- options : {
44
- instanceId : uuidv4 ( ) ,
45
- keychainId : uuidv4 ( ) ,
46
- logLevel,
25
+ test ( testCase , async ( ) => {
26
+ const pluginsPath = path . join (
27
+ __dirname , // start at the current file's path
28
+ "../../../../../../" , // walk back up to the project root
29
+ ".tmp/test/cmd-api-server/runtime-plugin-imports_test" , // the dir path from the root
30
+ uuidv4 ( ) , // then a random directory to ensure proper isolation
31
+ ) ;
32
+ const pluginManagerOptionsJson = JSON . stringify ( { pluginsPath } ) ;
33
+ const configService = new ConfigService ( ) ;
34
+ const apiServerOptions = await configService . newExampleConfig ( ) ;
35
+ apiServerOptions . authorizationProtocol = AuthorizationProtocol . NONE ;
36
+ apiServerOptions . pluginManagerOptionsJson = pluginManagerOptionsJson ;
37
+ apiServerOptions . configFile = "" ;
38
+ apiServerOptions . apiCorsDomainCsv = "*" ;
39
+ apiServerOptions . apiPort = 0 ;
40
+ apiServerOptions . cockpitPort = 0 ;
41
+ apiServerOptions . grpcPort = 0 ;
42
+ apiServerOptions . apiTlsEnabled = false ;
43
+ apiServerOptions . plugins = [
44
+ {
45
+ packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
46
+ type : PluginImportType . Local ,
47
+ action : PluginImportAction . Install ,
48
+ options : {
49
+ instanceId : uuidv4 ( ) ,
50
+ keychainId : uuidv4 ( ) ,
51
+ logLevel,
52
+ } ,
47
53
} ,
48
- } ,
49
- ] ;
50
- const config = await configService . newExampleConfigConvict ( apiServerOptions ) ;
54
+ ] ;
55
+ const config = await configService . newExampleConfigConvict (
56
+ apiServerOptions ,
57
+ ) ;
51
58
52
- const apiServer = new ApiServer ( {
53
- config : config . getProperties ( ) ,
59
+ apiServer = new ApiServer ( {
60
+ config : config . getProperties ( ) ,
61
+ } ) ;
62
+ apiServerOptions . plugins = [
63
+ {
64
+ packageName : "@hyperledger/cactus-plugin-keychain-memory" ,
65
+ type : PluginImportType . Local ,
66
+ action : PluginImportAction . Install ,
67
+ options : {
68
+ instanceId : uuidv4 ( ) ,
69
+ keychainId : uuidv4 ( ) ,
70
+ logLevel,
71
+ } ,
72
+ } ,
73
+ ] ;
74
+ await expect ( apiServer . start ( ) ) . not . toReject ( ) ;
75
+ } ) ;
76
+ afterAll ( async ( ) => {
77
+ await apiServer . shutdown ( ) ;
54
78
} ) ;
55
-
56
- await t . doesNotReject (
57
- apiServer . start ( ) ,
58
- "failed to start API server with dynamic plugin imports configured for it..." ,
59
- ) ;
60
- test . onFinish ( ( ) => apiServer . shutdown ( ) ) ;
61
79
} ) ;
0 commit comments