From e15aef3fa530d761366660757485f4a711da323a Mon Sep 17 00:00:00 2001 From: smilkuri Date: Wed, 3 Dec 2025 16:46:49 +0000 Subject: [PATCH] chore: convert bdd tests to e2e tests --- clients/client-acm/package.json | 3 +- .../client-acm/test/acm-features.e2e.spec.ts | 41 ++++++++++++ clients/client-acm/vitest.config.e2e.mts | 10 +++ clients/client-api-gateway/package.json | 3 +- .../test/apigateway-features.e2e.spec.ts | 41 ++++++++++++ .../client-api-gateway/vitest.config.e2e.mts | 10 +++ clients/client-cloudformation/package.json | 3 +- .../test/cloudformation-features.e2e.spec.ts | 62 +++++++++++++++++++ .../vitest.config.e2e.mts | 10 +++ features/acm/acm.feature | 17 ----- features/acm/step_definitions/acm.js | 7 --- features/apigateway/apigateway.feature | 17 ----- .../apigateway/step_definitions/apigateway.js | 7 --- .../cloudformation/cloudformation.feature | 20 ------ .../step_definitions/cloudformation.js | 18 ------ 15 files changed, 180 insertions(+), 89 deletions(-) create mode 100644 clients/client-acm/test/acm-features.e2e.spec.ts create mode 100644 clients/client-acm/vitest.config.e2e.mts create mode 100644 clients/client-api-gateway/test/apigateway-features.e2e.spec.ts create mode 100644 clients/client-api-gateway/vitest.config.e2e.mts create mode 100644 clients/client-cloudformation/test/cloudformation-features.e2e.spec.ts create mode 100644 clients/client-cloudformation/vitest.config.e2e.mts delete mode 100644 features/acm/acm.feature delete mode 100644 features/acm/step_definitions/acm.js delete mode 100644 features/apigateway/apigateway.feature delete mode 100644 features/apigateway/step_definitions/apigateway.js delete mode 100644 features/cloudformation/cloudformation.feature delete mode 100644 features/cloudformation/step_definitions/cloudformation.js diff --git a/clients/client-acm/package.json b/clients/client-acm/package.json index e237d8778ade4..5d6e0991c9ef2 100644 --- a/clients/client-acm/package.json +++ b/clients/client-acm/package.json @@ -11,7 +11,8 @@ "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", "extract:docs": "api-extractor run --local", - "generate:client": "node ../../scripts/generate-clients/single-service --solo acm" + "generate:client": "node ../../scripts/generate-clients/single-service --solo acm", + "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts" }, "main": "./dist-cjs/index.js", "types": "./dist-types/index.d.ts", diff --git a/clients/client-acm/test/acm-features.e2e.spec.ts b/clients/client-acm/test/acm-features.e2e.spec.ts new file mode 100644 index 0000000000000..31022d9a66bff --- /dev/null +++ b/clients/client-acm/test/acm-features.e2e.spec.ts @@ -0,0 +1,41 @@ +import { getE2eTestResources } from "@aws-sdk/aws-util-test/src"; +import { ACM } from "@aws-sdk/client-acm"; +import { beforeAll, describe, expect, test as it } from "vitest"; + +describe("@aws-sdk/client-acm", () => { + let client: ACM; + let region: string; + + beforeAll(async () => { + const e2eTestResourcesEnv = await getE2eTestResources(); + Object.assign(process.env, e2eTestResourcesEnv); + + region = process?.env?.AWS_SMOKE_TEST_REGION as string; + + client = new ACM({ region }); + }); + + describe("Making a request to ACM service", () => { + it("should successfully list certificates", async () => { + const result = await client.listCertificates({}); + + expect(result).toBeDefined(); + expect(result.CertificateSummaryList).toBeDefined(); + expect(Array.isArray(result.CertificateSummaryList)).toBe(true); + }); + }); + + describe("Error handling", () => { + it("should handle ValidationException for invalid certificate ARN", async () => { + await expect( + client.describeCertificate({ + CertificateArn: "fake_arn", + }) + ).rejects.toThrow( + expect.objectContaining({ + name: "ValidationException", + }) + ); + }); + }); +}); diff --git a/clients/client-acm/vitest.config.e2e.mts b/clients/client-acm/vitest.config.e2e.mts new file mode 100644 index 0000000000000..ccea26a45905c --- /dev/null +++ b/clients/client-acm/vitest.config.e2e.mts @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*.browser.e2e.spec.ts"], + include: ["**/*.e2e.spec.ts"], + environment: "node", + }, + mode: "development", +}); diff --git a/clients/client-api-gateway/package.json b/clients/client-api-gateway/package.json index e6e3255c55485..0a875314bad28 100644 --- a/clients/client-api-gateway/package.json +++ b/clients/client-api-gateway/package.json @@ -11,7 +11,8 @@ "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", "extract:docs": "api-extractor run --local", - "generate:client": "node ../../scripts/generate-clients/single-service --solo api-gateway" + "generate:client": "node ../../scripts/generate-clients/single-service --solo api-gateway", + "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts" }, "main": "./dist-cjs/index.js", "types": "./dist-types/index.d.ts", diff --git a/clients/client-api-gateway/test/apigateway-features.e2e.spec.ts b/clients/client-api-gateway/test/apigateway-features.e2e.spec.ts new file mode 100644 index 0000000000000..57959aee6daf2 --- /dev/null +++ b/clients/client-api-gateway/test/apigateway-features.e2e.spec.ts @@ -0,0 +1,41 @@ +import { getE2eTestResources } from "@aws-sdk/aws-util-test/src"; +import { APIGateway } from "@aws-sdk/client-api-gateway"; +import { beforeAll, describe, expect, test as it } from "vitest"; + +describe("@aws-sdk/client-api-gateway", () => { + let client: APIGateway; + let region: string; + + beforeAll(async () => { + const e2eTestResourcesEnv = await getE2eTestResources(); + Object.assign(process.env, e2eTestResourcesEnv); + + region = process?.env?.AWS_SMOKE_TEST_REGION as string; + + client = new APIGateway({ region }); + }); + + describe("Making a request", () => { + it("should successfully get REST APIs", async () => { + const result = await client.getRestApis({}); + + expect(result).toBeDefined(); + expect(result.items).toBeDefined(); + expect(Array.isArray(result.items)).toBe(true); + }); + }); + + describe("Error handling", () => { + it("should handle NotFoundException for invalid REST API ID", async () => { + await expect( + client.getRestApi({ + restApiId: "fake_id", + }) + ).rejects.toThrow( + expect.objectContaining({ + name: "NotFoundException", + }) + ); + }); + }); +}); diff --git a/clients/client-api-gateway/vitest.config.e2e.mts b/clients/client-api-gateway/vitest.config.e2e.mts new file mode 100644 index 0000000000000..ccea26a45905c --- /dev/null +++ b/clients/client-api-gateway/vitest.config.e2e.mts @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*.browser.e2e.spec.ts"], + include: ["**/*.e2e.spec.ts"], + environment: "node", + }, + mode: "development", +}); diff --git a/clients/client-cloudformation/package.json b/clients/client-cloudformation/package.json index 19190832163c9..6959ee4356ee0 100644 --- a/clients/client-cloudformation/package.json +++ b/clients/client-cloudformation/package.json @@ -11,7 +11,8 @@ "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", "extract:docs": "api-extractor run --local", - "generate:client": "node ../../scripts/generate-clients/single-service --solo cloudformation" + "generate:client": "node ../../scripts/generate-clients/single-service --solo cloudformation", + "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts" }, "main": "./dist-cjs/index.js", "types": "./dist-types/index.d.ts", diff --git a/clients/client-cloudformation/test/cloudformation-features.e2e.spec.ts b/clients/client-cloudformation/test/cloudformation-features.e2e.spec.ts new file mode 100644 index 0000000000000..eae52e6025ad5 --- /dev/null +++ b/clients/client-cloudformation/test/cloudformation-features.e2e.spec.ts @@ -0,0 +1,62 @@ +import { getE2eTestResources } from "@aws-sdk/aws-util-test/src"; +import { CloudFormation, paginateListStacks } from "@aws-sdk/client-cloudformation"; +import { beforeAll, describe, expect, test as it } from "vitest"; + +describe("@aws-sdk/client-cloudformation", () => { + let client: CloudFormation; + let region: string; + + beforeAll(async () => { + const e2eTestResourcesEnv = await getE2eTestResources(); + Object.assign(process.env, e2eTestResourcesEnv); + + region = process?.env?.AWS_SMOKE_TEST_REGION as string; + + client = new CloudFormation({ region }); + }); + + describe("Describing stacks", () => { + it("should return stacks list when describing stacks is called", async () => { + const result = await client.describeStacks({}); + + expect(result).toBeDefined(); + expect(result.Stacks).toBeDefined(); + expect(Array.isArray(result.Stacks)).toBe(true); + }); + }); + + describe("Error handling", () => { + it("should handle ValidationError for invalid stack creation", async () => { + const templateBody = '{"Resources":{"member":{"Type":"AWS::SQS::Queue"}}}'; + + await expect( + client.createStack({ + TemplateBody: templateBody, + StackName: "", // Empty name should cause ValidationError + }) + ).rejects.toThrow( + expect.objectContaining({ + name: "ValidationError", + }) + ); + }); + }); + + describe("Paginating responses", () => { + it("should paginate listStacks operation", async () => { + const paginator = paginateListStacks({ client }, {}); + + let pageCount = 0; + let lastPage; + + for await (const page of paginator) { + pageCount++; + lastPage = page; + if (pageCount >= 3) break; // Get at least three pages + } + + expect(pageCount).toBeGreaterThanOrEqual(1); + expect(lastPage).toBeDefined(); + }); + }); +}); diff --git a/clients/client-cloudformation/vitest.config.e2e.mts b/clients/client-cloudformation/vitest.config.e2e.mts new file mode 100644 index 0000000000000..ccea26a45905c --- /dev/null +++ b/clients/client-cloudformation/vitest.config.e2e.mts @@ -0,0 +1,10 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*.browser.e2e.spec.ts"], + include: ["**/*.e2e.spec.ts"], + environment: "node", + }, + mode: "development", +}); diff --git a/features/acm/acm.feature b/features/acm/acm.feature deleted file mode 100644 index 7da9679fd9f18..0000000000000 --- a/features/acm/acm.feature +++ /dev/null @@ -1,17 +0,0 @@ -# language: en -@acm -Feature: - - I want to use AWS Certificate Manager - - Scenario: Making a request - Given I run the "listCertificates" operation - Then the request should be successful - And the value at "CertificateSummaryList" should be a list - - Scenario: Error handling - Given I run the "describeCertificate" operation with params: - """ - { "CertificateArn": "fake_arn" } - """ - Then the error code should be "ValidationException" diff --git a/features/acm/step_definitions/acm.js b/features/acm/step_definitions/acm.js deleted file mode 100644 index 303fb3edcd792..0000000000000 --- a/features/acm/step_definitions/acm.js +++ /dev/null @@ -1,7 +0,0 @@ -const { Before } = require("@cucumber/cucumber"); - -Before({ tags: "@acm" }, function (scenario, callback) { - const { ACM } = require("../../../clients/client-acm"); - this.service = new ACM({}); - callback(); -}); diff --git a/features/apigateway/apigateway.feature b/features/apigateway/apigateway.feature deleted file mode 100644 index 663d7ee2630fd..0000000000000 --- a/features/apigateway/apigateway.feature +++ /dev/null @@ -1,17 +0,0 @@ -# language: en -@apigateway -Feature: - - I want to use Amazon API Gateway - - Scenario: Making a request - Given I run the "getRestApis" operation - Then the request should be successful - And the value at "items" should be a list - - Scenario: Error handling - Given I run the "getRestApi" operation with params: - """ - { "restApiId": "fake_id" } - """ - Then the error code should be "NotFoundException" diff --git a/features/apigateway/step_definitions/apigateway.js b/features/apigateway/step_definitions/apigateway.js deleted file mode 100644 index c63db04e63f6f..0000000000000 --- a/features/apigateway/step_definitions/apigateway.js +++ /dev/null @@ -1,7 +0,0 @@ -const { Before } = require("@cucumber/cucumber"); - -Before({ tags: "@apigateway" }, function (scenario, callback) { - const { APIGateway } = require("../../../clients/client-api-gateway"); - this.service = new APIGateway({}); - callback(); -}); diff --git a/features/cloudformation/cloudformation.feature b/features/cloudformation/cloudformation.feature deleted file mode 100644 index 1a13a19cd2f86..0000000000000 --- a/features/cloudformation/cloudformation.feature +++ /dev/null @@ -1,20 +0,0 @@ -# language: en -@cloudformation -Feature: AWS CloudFormation - - I want to use AWS CloudFormation - - Scenario: Describing stacks - Given I run the "describeStacks" operation - Then the request should be successful - And the value at "Stacks" should be a list - - Scenario: Error handling - Given I create a CloudFormation stack with name prefix "" - Then the error code should be "ValidationError" - -# @pagination -# Scenario: Paginating responses -# Given I paginate the "listStacks" operation -# Then I should get at least one page -# And the last page should not contain a marker diff --git a/features/cloudformation/step_definitions/cloudformation.js b/features/cloudformation/step_definitions/cloudformation.js deleted file mode 100644 index 20603de1b6a25..0000000000000 --- a/features/cloudformation/step_definitions/cloudformation.js +++ /dev/null @@ -1,18 +0,0 @@ -const { Before, Given } = require("@cucumber/cucumber"); - -Before({ tags: "@cloudformation" }, function (scenario, callback) { - const { CloudFormation } = require("../../../clients/client-cloudformation"); - this.service = new CloudFormation({}); - callback(); -}); - -Given("I create a CloudFormation stack with name prefix {string}", function (prefix, callback) { - this.stackName = this.uniqueName(prefix); - this.templateBody = '{"Resources":{"member":{"Type":"AWS::SQS::Queue"}}}'; - const params = { - TemplateBody: this.templateBody, - StackName: this.stackName, - EnableTerminationProtection: true, - }; - this.request(null, "createStack", params, callback, false); -});