Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(clients): convert ts-mocha tests to vitest #6602

Merged
merged 19 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clients/client-cognito-identity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
*.tgz
*.log
package-lock.json
!karma.conf.js
3 changes: 1 addition & 2 deletions clients/client-cognito-identity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo cognito-identity",
"test:e2e": "vitest run -c vitest.config.e2e.ts",
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development",
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts"
},
"main": "./dist-cjs/index.js",
Expand Down Expand Up @@ -66,7 +66,6 @@
"@aws-sdk/client-iam": "*",
"@tsconfig/node16": "16.1.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.4",
"@types/node": "^16.18.96",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
4 changes: 2 additions & 2 deletions clients/client-eventbridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo eventbridge",
"test": "yarn test:unit",
"test:unit": "ts-mocha test/**/*.spec.ts"
"test": "vitest run",
"test:watch": "vitest watch"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
Expand Down
24 changes: 17 additions & 7 deletions clients/client-eventbridge/test/EventBridge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
/// <reference types="mocha" />
import "@aws-sdk/signature-v4-crt";

import { CrtSignerV4 } from "@aws-sdk/signature-v4-crt";
import { signatureV4CrtContainer } from "@aws-sdk/signature-v4-multi-region";
import { crtAvailability } from "@aws-sdk/util-user-agent-node";

// Vite build seems to be unable to recognize this injection
// code from the signature-v4-crt index module.
signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4;
crtAvailability.isCrtAvailable = true;

import { FinalizeRequestMiddleware } from "@aws-sdk/types";
import chai from "chai";
import chaiAsPromised from "chai-as-promised";
import { describe, expect, test as it } from "vitest";

import { EventBridge } from "../src/EventBridge";

chai.use(chaiAsPromised);
const { expect } = chai;

describe("EventBridge", () => {
const client = new EventBridge({});
const client = new EventBridge({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
// and return them in the Metadata.
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {
Expand Down
2 changes: 1 addition & 1 deletion clients/client-eventbridge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rootDir": "src",
"useUnknownInCatchVariables": false
},
"exclude": ["test/"]
"exclude": ["test/", "vitest.*.ts"]
}
2 changes: 1 addition & 1 deletion clients/client-eventbridge/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"declarationDir": "dist-types",
"emitDeclarationOnly": true
},
"exclude": ["test/**/*", "dist-types/**/*"]
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
}
9 changes: 9 additions & 0 deletions clients/client-eventbridge/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
include: ["**/*.spec.ts"],
environment: "node",
},
});
2 changes: 1 addition & 1 deletion clients/client-kinesis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo kinesis",
"test:e2e": "vitest run -c vitest.config.e2e.ts",
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development",
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts"
},
"main": "./dist-cjs/index.js",
Expand Down
8 changes: 6 additions & 2 deletions clients/client-kinesis/test/Kinesis.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { test as it, describe, expect } from "vitest";
import { beforeAll, describe, expect, test as it } from "vitest";

import { KinesisClient, ListStreamsCommand } from "../src/index";

describe("@aws-sdk/client-kinesis", () => {
const client = new KinesisClient({});
beforeAll(async () => {});

const client = new KinesisClient({
region: "us-west-2",
});
const ONE_SECOND = 1 * 1000;

// TODO: not working in CI
Expand Down
6 changes: 2 additions & 4 deletions clients/client-lex-runtime-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo lex-runtime-service",
"test": "yarn test:unit",
"test:unit": "ts-mocha test/**/*.spec.ts"
"test": "vitest run",
"test:watch": "vitest watch"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
Expand Down Expand Up @@ -65,8 +65,6 @@
},
"devDependencies": {
"@tsconfig/node16": "16.1.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.4",
"@types/node": "^16.18.96",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="mocha" />
import { HttpRequest } from "@smithy/protocol-http";
import { SerializeMiddleware } from "@smithy/types";
import { expect } from "chai";
import { describe, expect, test as it } from "vitest";

import { LexRuntimeService } from "../src/LexRuntimeService";

Expand All @@ -16,6 +15,10 @@ describe("@aws-sdk/client-lex-runtime-service", () => {
};
const client = new LexRuntimeService({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
Expand Down
2 changes: 1 addition & 1 deletion clients/client-lex-runtime-service/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rootDir": "src",
"useUnknownInCatchVariables": false
},
"exclude": ["test/"]
"exclude": ["test/", "vitest.*.ts"]
}
2 changes: 1 addition & 1 deletion clients/client-lex-runtime-service/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"declarationDir": "dist-types",
"emitDeclarationOnly": true
},
"exclude": ["test/**/*", "dist-types/**/*"]
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
}
9 changes: 9 additions & 0 deletions clients/client-lex-runtime-service/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
include: ["**/*.spec.ts"],
environment: "node",
},
});
6 changes: 2 additions & 4 deletions clients/client-mediastore-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo mediastore-data",
"test": "yarn test:unit",
"test:unit": "ts-mocha test/**/*.spec.ts"
"test": "vitest run",
"test:watch": "vitest watch"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
Expand Down Expand Up @@ -65,8 +65,6 @@
},
"devDependencies": {
"@tsconfig/node16": "16.1.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.4",
"@types/node": "^16.18.96",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
7 changes: 5 additions & 2 deletions clients/client-mediastore-data/test/MediaStoreData.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/// <reference types="mocha" />
import { HttpRequest } from "@smithy/protocol-http";
import { SerializeMiddleware } from "@smithy/types";
import { expect } from "chai";
import { describe, expect, test as it } from "vitest";

import { MediaStoreData } from "../src/MediaStoreData";

Expand All @@ -16,6 +15,10 @@ describe("@aws-sdk/client-mediastore-data", () => {
};
const client = new MediaStoreData({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(validator, {
step: "serialize",
Expand Down
2 changes: 1 addition & 1 deletion clients/client-mediastore-data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rootDir": "src",
"useUnknownInCatchVariables": false
},
"exclude": ["test/"]
"exclude": ["test/", "vitest.*.ts"]
}
2 changes: 1 addition & 1 deletion clients/client-mediastore-data/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"declarationDir": "dist-types",
"emitDeclarationOnly": true
},
"exclude": ["test/**/*", "dist-types/**/*"]
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
}
9 changes: 9 additions & 0 deletions clients/client-mediastore-data/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
include: ["**/*.spec.ts"],
environment: "node",
},
});
5 changes: 2 additions & 3 deletions clients/client-s3-control/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"extract:docs": "api-extractor run --local",
"generate:client": "node ../../scripts/generate-clients/single-service --solo s3-control",
"test": "yarn test:unit",
"test:unit": "ts-mocha test/**/*.spec.ts"
"test": "vitest run",
"test:watch": "vitest watch"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
Expand Down Expand Up @@ -72,7 +72,6 @@
},
"devDependencies": {
"@tsconfig/node16": "16.1.3",
"@types/mocha": "^8.0.4",
"@types/node": "^16.18.96",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
3 changes: 1 addition & 2 deletions clients/client-s3-control/test/S3Control.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="mocha" />
import { FinalizeRequestMiddleware } from "@aws-sdk/types";
import { expect } from "chai";
import { describe, expect, test as it } from "vitest";

import { S3Control } from "../src/S3Control";

Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3-control/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"rootDir": "src",
"useUnknownInCatchVariables": false
},
"exclude": ["test/"]
"exclude": ["test/", "vitest.*.ts"]
}
2 changes: 1 addition & 1 deletion clients/client-s3-control/tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"declarationDir": "dist-types",
"emitDeclarationOnly": true
},
"exclude": ["test/**/*", "dist-types/**/*"]
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
}
9 changes: 9 additions & 0 deletions clients/client-s3-control/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
include: ["**/*.spec.ts"],
environment: "node",
},
});
1 change: 0 additions & 1 deletion clients/client-s3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
*.tgz
*.log
package-lock.json
!karma.conf.js
/test/browser-build/browser-s3-bundle.js
6 changes: 2 additions & 4 deletions clients/client-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"generate:client": "node ../../scripts/generate-clients/single-service --solo s3",
"test": "vitest run",
"test:watch": "vitest watch",
"test:e2e": "vitest run -c vitest.config.e2e.ts && yarn test:browser",
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development && yarn test:browser",
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts",
"test:browser": "node ./test/browser-build/esbuild && vitest run -c vitest.config.browser.ts",
"test:browser": "node ./test/browser-build/esbuild && vitest run -c vitest.config.browser.ts --mode development",
"test:browser:watch": "node ./test/browser-build/esbuild && vitest watch -c vitest.config.browser.ts"
},
"main": "./dist-cjs/index.js",
Expand Down Expand Up @@ -86,8 +86,6 @@
"devDependencies": {
"@aws-sdk/signature-v4-crt": "*",
"@tsconfig/node16": "16.1.3",
"@types/chai": "^4.2.11",
"@types/mocha": "^8.0.4",
"@types/node": "^16.18.96",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
Expand Down
6 changes: 1 addition & 5 deletions clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* This is the integration test that make sure the client can make request cross-platform-ly
* in NodeJS and browsers.
*/
import type { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
Expand Down Expand Up @@ -33,7 +29,7 @@ describe("@aws-sdk/client-s3", () => {
credentials: fromNodeProviderChain(),
requestHandler: new FetchHttpHandler(),
})
) as S3;
) as unknown as S3;
});

describe("PutObject", () => {
Expand Down
4 changes: 0 additions & 4 deletions clients/client-s3/test/e2e/S3.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "@aws-sdk/signature-v4-crt";

import { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
import { AwsCredentialIdentity } from "@aws-sdk/types";
import { afterAll, afterEach, beforeAll, describe, expect, test as it } from "vitest";

import { getIntegTestResources } from "../../../../tests/e2e/get-integ-test-resources";
Expand All @@ -13,23 +12,20 @@ describe("@aws-sdk/client-s3", () => {
let client: S3;
let Bucket: string;
let region: string;
let credentials: AwsCredentialIdentity;
let mrapArn: string;

beforeAll(async () => {
const integTestResourcesEnv = await getIntegTestResources();
Object.assign(process.env, integTestResourcesEnv);

region = process?.env?.AWS_SMOKE_TEST_REGION as string;
credentials = (globalThis as any).credentials || undefined;
Bucket = process?.env?.AWS_SMOKE_TEST_BUCKET as string;
mrapArn = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_MRAP_ARN || process?.env?.AWS_SMOKE_TEST_MRAP_ARN;

Key = ``;

client = new S3({
region,
credentials,
});
});

Expand Down
Loading
Loading