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 #6595

Closed
wants to merge 5 commits into from
Closed
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
1 change: 0 additions & 1 deletion clients/client-cognito-identity/package.json
Original file line number Diff line number Diff line change
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
15 changes: 8 additions & 7 deletions clients/client-eventbridge/test/EventBridge.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/// <reference types="mocha" />
import "@aws-sdk/signature-v4-crt";

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",
},
});
10 changes: 8 additions & 2 deletions clients/client-kinesis/test/Kinesis.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { test as it, describe, expect } from "vitest";
import { describe, expect, test as it } from "vitest";

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

describe("@aws-sdk/client-kinesis", () => {
const client = new KinesisClient({});
const client = new KinesisClient({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
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
2 changes: 0 additions & 2 deletions clients/client-s3/package.json
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion clients/client-s3/test/e2e/S3.browser.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("@aws-sdk/client-s3", () => {
credentials: fromNodeProviderChain(),
requestHandler: new FetchHttpHandler(),
})
) as S3;
) as unknown as S3;
});

describe("PutObject", () => {
Expand Down
47 changes: 42 additions & 5 deletions clients/client-s3/test/unit/S3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ describe("endpoint", () => {
expect(request.path).to.equal("/path/bucket/key");
return Promise.resolve({ output: {} as any, response: {} as any });
};
const client = new S3({ endpoint: "http://localhost:8080/path", forcePathStyle: true });
const client = new S3({
endpoint: "http://localhost:8080/path",
forcePathStyle: true,
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});

client.middlewareStack.add(endpointValidator, {
step: "serialize",
Expand Down Expand Up @@ -48,7 +56,13 @@ describe("Endpoints from ARN", () => {

describe("Accesspoint ARN", async () => {
it("should succeed with access point ARN", async () => {
const client = new S3({ region: "us-west-2" });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "build", priority: "low" });
const result: any = await client.putObject({
Bucket: "arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint",
Expand Down Expand Up @@ -151,6 +165,10 @@ describe("Throw 200 response", () => {

const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
requestHandler: {
handle: async () => ({
response,
Expand Down Expand Up @@ -228,7 +246,13 @@ describe("regional endpoints", () => {
};

it("should use regional endpoints if region is us-east-1", async () => {
const client = new S3({ region: "us-east-1" });
const client = new S3({
region: "us-east-1",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Expand All @@ -239,7 +263,13 @@ describe("regional endpoints", () => {
});

it("should use global endpoints if region is aws-global", async () => {
const client = new S3({ region: "aws-global" });
const client = new S3({
region: "aws-global",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
});
client.middlewareStack.add(endpointValidator, { step: "finalizeRequest", priority: "low" });
const result: any = await client.putObject({
Bucket: "bucket",
Expand All @@ -263,7 +293,14 @@ describe("signing", () => {
},
};

const client = new S3({ requestHandler });
const client = new S3({
region: "us-west-2",
credentials: {
accessKeyId: "CLIENT_TEST",
secretAccessKey: "CLIENT_TEST",
},
requestHandler,
});
return await client.putObject({
Bucket: "bucket",
Key: "some file.txt",
Expand Down
Loading
Loading