From 499f70302ca55c51f61f46abc3da8403c404409b Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Sat, 28 Sep 2024 08:11:49 -0700 Subject: [PATCH] test(test-cmd-api-server): jestify plugin-import-with-npm-install-version Signed-off-by: Peter Somogyvari --- .github/workflows/ci.yaml | 3 +- .taprc | 1 - jest.config.js | 1 - ...with-npm-install-version-selection.test.ts | 108 +++++++++--------- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ba8a70e63e..2247f1ec2f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2200,8 +2200,7 @@ jobs: JEST_TEST_RUNNER_DISABLED: false JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/ct-cmd-api-server JEST_TEST_CODE_COVERAGE_ENABLED: true - TAPE_TEST_PATTERN: ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts - TAPE_TEST_RUNNER_DISABLED: false + TAPE_TEST_RUNNER_DISABLED: true runs-on: ubuntu-22.04 steps: - name: Use Node.js ${{ env.NODEJS_VERSION }} diff --git a/.taprc b/.taprc index ba16cc18b6..9960759de4 100644 --- a/.taprc +++ b/.taprc @@ -13,7 +13,6 @@ files: - ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/get-status-endpoint.test.ts - ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts - ./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts - - ./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.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/flow-database-access-v4.8.test.ts - ./packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts diff --git a/jest.config.js b/jest.config.js index e72ea6af09..afd33edea9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,7 +25,6 @@ module.exports = { `./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/get-status-endpoint.test.ts`, `./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/openapi/openapi-validation.test.ts`, `./packages/cactus-test-plugin-htlc-eth-besu-erc20/src/test/typescript/integration/plugin-htlc-eth-besu-erc20/refund-endpoint.test.ts`, - `./packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.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/flow-database-access-v4.8.test.ts`, `./packages/cactus-test-plugin-consortium-manual/src/test/typescript/integration/plugin-consortium-manual/openapi/openapi-validation.test.ts`, diff --git a/packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts b/packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts index 59988e1d42..67ea222c61 100644 --- a/packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts +++ b/packages/cactus-test-cmd-api-server/src/test/typescript/integration/plugin-import-with-npm-install-version-selection.test.ts @@ -1,10 +1,12 @@ -import path from "path"; -import test, { Test } from "tape-promise/tape"; -import { v4 as uuidv4 } from "uuid"; -import { readFile } from "fs/promises"; +import { randomUUID as uuidv4 } from "node:crypto"; +import path from "node:path"; +import { readFile } from "node:fs/promises"; + +import "jest-extended"; import { LogLevelDesc } from "@hyperledger/cactus-common"; import { + PluginImport, PluginImportAction, PluginImportType, } from "@hyperledger/cactus-core-api"; @@ -14,9 +16,9 @@ import { ConfigService, } from "@hyperledger/cactus-cmd-api-server"; -const logLevel: LogLevelDesc = "TRACE"; +const logLevel: LogLevelDesc = "INFO"; -test("can install plugins at runtime with specified version based on imports", async (t: Test) => { +describe("ApiServer", () => { const pluginsPath = path.join( __dirname, "../../../../../../", // walk back up to the project root @@ -25,59 +27,61 @@ test("can install plugins at runtime with specified version based on imports", a ); const pluginManagerOptionsJson = JSON.stringify({ pluginsPath }); - const configService = new ConfigService(); - - const apiServerOptions = await configService.newExampleConfig(); - apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson; - apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; - apiServerOptions.configFile = ""; - apiServerOptions.apiCorsDomainCsv = "*"; - apiServerOptions.apiPort = 0; - apiServerOptions.cockpitPort = 0; - apiServerOptions.grpcPort = 0; - apiServerOptions.crpcPort = 0; - apiServerOptions.apiTlsEnabled = false; - apiServerOptions.plugins = [ - { - packageName: "@hyperledger/cactus-plugin-keychain-memory", - type: PluginImportType.Local, - action: PluginImportAction.Install, - options: { - instanceId: uuidv4(), - keychainId: uuidv4(), - logLevel, - version: "0.9.0", - }, + const aPluginImport: PluginImport = { + packageName: "@hyperledger/cactus-plugin-keychain-memory", + type: PluginImportType.Local, + action: PluginImportAction.Install, + options: { + instanceId: uuidv4(), + keychainId: uuidv4(), + logLevel, + version: "0.9.0", }, - ]; - const config = await configService.newExampleConfigConvict(apiServerOptions); - - const apiServer = new ApiServer({ - config: config.getProperties(), - }); - - const startResponse = apiServer.start(); - await t.doesNotReject( - startResponse, - "failed to start API server with dynamic plugin imports configured for it...", - ); - t.ok(startResponse, "startResponse truthy OK"); + }; const packageFilePath = path.join( pluginsPath, - apiServerOptions.plugins[0].options.instanceId, + aPluginImport.options.instanceId, "node_modules", - `${apiServerOptions.plugins[0].packageName}`, + `${aPluginImport.packageName}`, "package.json", ); - const pkgJsonStr = await readFile(packageFilePath, "utf-8"); - const { version } = JSON.parse(pkgJsonStr); - t.strictEquals( - version, - apiServerOptions.plugins[0].options.version, - `Package version strictly equal to ${version}`, - ); + const configService = new ConfigService(); - test.onFinish(() => apiServer.shutdown()); + let apiServer: ApiServer; + + beforeAll(async () => { + const apiSrvOpts = await configService.newExampleConfig(); + apiSrvOpts.pluginManagerOptionsJson = pluginManagerOptionsJson; + apiSrvOpts.authorizationProtocol = AuthorizationProtocol.NONE; + apiSrvOpts.logLevel = logLevel; + apiSrvOpts.configFile = ""; + apiSrvOpts.apiCorsDomainCsv = "*"; + apiSrvOpts.apiPort = 0; + apiSrvOpts.cockpitPort = 0; + apiSrvOpts.grpcPort = 0; + apiSrvOpts.crpcPort = 0; + apiSrvOpts.apiTlsEnabled = false; + apiSrvOpts.plugins = [aPluginImport]; + const config = await configService.newExampleConfigConvict(apiSrvOpts); + + apiServer = new ApiServer({ + config: config.getProperties(), + }); + }); + + afterAll(async () => { + await apiServer.shutdown(); + }); + + test("can install plugins at runtime with specified version based on imports", async () => { + const startResponse = apiServer.start(); + await expect(startResponse).toResolve(); + + const pkgJsonStr = await readFile(packageFilePath, "utf-8"); + const { version } = JSON.parse(pkgJsonStr); + + expect(version).toEqual(aPluginImport.options.version); + }); });