Skip to content

Commit

Permalink
test: jestify runtime-plugin-import test and fix flaky test
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Youngone Lee <[email protected]>

Fixes #1667
  • Loading branch information
awadhana authored and Leeyoungone committed Apr 6, 2022
1 parent a4f07f6 commit c4c2d9a
Show file tree
Hide file tree
Showing 4 changed files with 1,041 additions and 1,220 deletions.
1 change: 0 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ files:
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/remote-plugin-imports.test.ts
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install.test.ts
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts
- ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/openapi/openapi-validation.test.ts
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/deploy-cordapp-jars-to-nodes-v4.7.test.ts
- ./packages/cactus-plugin-ledger-connector-corda/src/test/typescript/integration/jvm-kotlin-spring-server-v4.7.test.ts
Expand Down
1 change: 0 additions & 1 deletion jest.config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import path from "path";
import test, { Test } from "tape-promise/tape";
import { v4 as uuidv4 } from "uuid";

import "jest-extended";
import { LogLevelDesc } from "@hyperledger/cactus-common";

import {
ApiServer,
AuthorizationProtocol,
Expand All @@ -14,48 +12,68 @@ import {
PluginImportType,
} from "@hyperledger/cactus-core-api";

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

test("can import plugins at runtime (CLI)", async (t: Test) => {
const pluginsPath = path.join(
__dirname, // start at the current file's path
"../../../../../../", // walk back up to the project root
".tmp/test/cmd-api-server/runtime-plugin-imports_test", // the dir path from the root
uuidv4(), // then a random directory to ensure proper isolation
);
const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });
afterEach(() => {
jest.useRealTimers();
});

const configService = new ConfigService();
const apiServerOptions = await configService.newExampleConfig();
apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE;
apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiServerOptions.configFile = "";
apiServerOptions.apiCorsDomainCsv = "*";
apiServerOptions.apiPort = 0;
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [
{
packageName: "@hyperledger/cactus-plugin-keychain-memory",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
test(testCase, async () => {
const pluginsPath = path.join(
__dirname, // start at the current file's path
"../../../../../../", // walk back up to the project root
".tmp/test/cmd-api-server/runtime-plugin-imports_test", // the dir path from the root
uuidv4(), // then a random directory to ensure proper isolation
);
const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });
const configService = new ConfigService();
const apiServerOptions = await configService.newExampleConfig();
apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE;
apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
apiServerOptions.configFile = "";
apiServerOptions.apiCorsDomainCsv = "*";
apiServerOptions.apiPort = 0;
apiServerOptions.cockpitPort = 0;
apiServerOptions.grpcPort = 0;
apiServerOptions.apiTlsEnabled = false;
apiServerOptions.plugins = [
{
packageName: "@hyperledger/cactus-plugin-keychain-memory",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
},
},
},
];
const config = await configService.newExampleConfigConvict(apiServerOptions);
];
const config = await configService.newExampleConfigConvict(
apiServerOptions,
);

const apiServer = new ApiServer({
config: config.getProperties(),
apiServer = new ApiServer({
config: config.getProperties(),
});
apiServerOptions.plugins = [
{
packageName: "@hyperledger/cactus-plugin-keychain-memory",
type: PluginImportType.Local,
action: PluginImportAction.Install,
options: {
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel,
},
},
];
await expect(apiServer.start()).not.toReject();
});
afterAll(async () => {
await apiServer.shutdown();
});

await t.doesNotReject(
apiServer.start(),
"failed to start API server with dynamic plugin imports configured for it...",
);
test.onFinish(() => apiServer.shutdown());
});
Loading

0 comments on commit c4c2d9a

Please sign in to comment.