From d24bff5125dd3d30b73a71fcb2da547ead0e8fc4 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Mon, 12 Aug 2024 19:42:34 +0000 Subject: [PATCH] test(endpoints): make namespace and model variables const --- .../endpoints-integration.spec.ts | 33 ++++++------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/tests/endpoints-2.0/endpoints-integration.spec.ts b/tests/endpoints-2.0/endpoints-integration.spec.ts index 6c90b296fb64..5efa36dafbe6 100644 --- a/tests/endpoints-2.0/endpoints-integration.spec.ts +++ b/tests/endpoints-2.0/endpoints-integration.spec.ts @@ -1,39 +1,28 @@ import { resolveParams } from "@smithy/middleware-endpoint"; import { EndpointV2 } from "@smithy/types"; import { resolveEndpoint, EndpointParams } from "@smithy/util-endpoints"; -import { readdirSync } from "fs"; +import { existsSync, readdirSync } from "fs"; import { join } from "path"; import { EndpointExpectation, ServiceModel, ServiceNamespace } from "./integration-test-types"; describe("client list", () => { const root = join(__dirname, "..", ".."); - const clientList = readdirSync(join(root, "clients")); + const clientPackageNameList = readdirSync(join(root, "clients")); it("should be at least 300 clients", () => { - expect(clientList.length).toBeGreaterThan(300); + expect(clientPackageNameList.length).toBeGreaterThan(300); }); - describe.each(clientList)(`%s endpoint test cases`, (client) => { - const serviceName = client.slice(7); + describe.each(clientPackageNameList)(`%s endpoint test cases`, (clientPackageName) => { + const serviceName = clientPackageName.slice(7); - let namespace: any; - let model: any; + // since client package name list is populated from clients folder, we know it exists. + const namespace = require(`@aws-sdk/${clientPackageName}`); + const modelPath = join(root, "codegen", "sdk-codegen", "aws-models", serviceName + ".json"); - // this may also work with dynamic async import() in a beforeAll() block, - // but needs more effort than using synchronous require(). - try { - namespace = require(`@aws-sdk/client-${serviceName}`); - model = require(join(root, "codegen", "sdk-codegen", "aws-models", serviceName + ".json")); - } catch (e) { - namespace = null; - model = null; - if (e.code !== "MODULE_NOT_FOUND") { - console.error(e); - } - } - - if (namespace && model) { + if (existsSync(modelPath)) { + const model = require(modelPath); for (const value of Object.values(model.shapes)) { if (typeof value === "object" && value !== null && "type" in value && value.type === "service") { const service = value as ServiceModel; @@ -41,8 +30,6 @@ describe("client list", () => { break; } } - } else { - it.skip("unable to load endpoint resolver, namespace, or test cases", () => {}); } }); });