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 Mar 25, 2022
1 parent 6e189dc commit 133d6a1
Show file tree
Hide file tree
Showing 6 changed files with 691 additions and 652 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
Binary file added Review the current policies format.pdf
Binary file not shown.
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.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"lerna": "4.0.0",
"lint-staged": "11.1.2",
"make-dir-cli": "3.0.0",
"node-cleanup": "2.1.2",
"node-polyfill-webpack-plugin": "1.1.4",
"npm-run-all": "4.1.5",
"npm-watch": "0.11.0",
Expand Down
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 133d6a1

Please sign in to comment.