Skip to content

Commit 36e1bc4

Browse files
awadhanaLeeyoungone
authored andcommitted
test: jestify runtime-plugin-import test and fix flaky test
Migrated test from Tap to Jest. File Path: packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts This is a PARTIAL resolution to issue #238 Signed-off-by: awadhana <awadhana0825@gmail.com> Signed-off-by: Youngone Lee <youngone.lee@accenture.com> Fixes #1667
1 parent 232e5c1 commit 36e1bc4

File tree

3 files changed

+59
-43
lines changed

3 files changed

+59
-43
lines changed

.taprc

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ files:
4242
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/remote-plugin-imports.test.ts
4343
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install.test.ts
4444
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts
45-
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts
4645
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts
4746
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/deploy-cordapp-jars-to-nodes-v4.7.test.ts
4847
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server-v4.7.test.ts

jest.config.js

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import path from "path";
2-
import test, { Test } from "tape-promise/tape";
32
import { v4 as uuidv4 } from "uuid";
4-
3+
import "jest-extended";
54
import { LogLevelDesc } from "@hyperledger/cactus-common";
6-
75
import {
86
ApiServer,
97
AuthorizationProtocol,
@@ -14,48 +12,68 @@ import {
1412
PluginImportType,
1513
} from "@hyperledger/cactus-core-api";
1614

15+
//const nodeCleanup = require("node-cleanup");
1716
const logLevel: LogLevelDesc = "TRACE";
17+
const testCase = "can import plugins at runtime (CLI)";
18+
describe(testCase, () => {
19+
let apiServer: ApiServer;
1820

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+
});
2724

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+
},
4753
},
48-
},
49-
];
50-
const config = await configService.newExampleConfigConvict(apiServerOptions);
54+
];
55+
const config = await configService.newExampleConfigConvict(
56+
apiServerOptions,
57+
);
5158

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();
5478
});
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());
6179
});

0 commit comments

Comments
 (0)