Skip to content

Commit f334800

Browse files
authored
test(clients): convert ts-mocha tests to vitest (#6602)
* test: upate mocha to vitest * chore: remove jasmine/chai/karma * chore(clients): ignore vitest.ts files * test(clients): add mock credentials to client instantiations * test: enable turbo error * test(credential-provider-cognito-identity): fix browser test * test(client-eventbridge): fix crt import * test: fix browser tests * test: set region in e2e test setup * test(s3-request-presigner): mock credentials in test * test(client-s3): fix test e2e command * test: log credential resolution debug * test: set sdk-integ-test as profile * test: what is even going on * test: create e2e global hook * test: run vite e2e in development mode * test: use turbo loose env mode * test: remove console logs * test: remove unused test hook
1 parent 52b2df0 commit f334800

File tree

63 files changed

+376
-1656
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+376
-1656
lines changed

clients/client-cognito-identity/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
*.tgz
88
*.log
99
package-lock.json
10-
!karma.conf.js

clients/client-cognito-identity/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo cognito-identity",
15-
"test:e2e": "vitest run -c vitest.config.e2e.ts",
15+
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development",
1616
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts"
1717
},
1818
"main": "./dist-cjs/index.js",
@@ -66,7 +66,6 @@
6666
"@aws-sdk/client-iam": "*",
6767
"@tsconfig/node16": "16.1.3",
6868
"@types/chai": "^4.2.11",
69-
"@types/mocha": "^8.0.4",
7069
"@types/node": "^16.18.96",
7170
"concurrently": "7.0.0",
7271
"downlevel-dts": "0.10.1",

clients/client-eventbridge/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo eventbridge",
15-
"test": "yarn test:unit",
16-
"test:unit": "ts-mocha test/**/*.spec.ts"
15+
"test": "vitest run",
16+
"test:watch": "vitest watch"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",

clients/client-eventbridge/test/EventBridge.spec.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
/// <reference types="mocha" />
21
import "@aws-sdk/signature-v4-crt";
32

3+
import { CrtSignerV4 } from "@aws-sdk/signature-v4-crt";
4+
import { signatureV4CrtContainer } from "@aws-sdk/signature-v4-multi-region";
5+
import { crtAvailability } from "@aws-sdk/util-user-agent-node";
6+
7+
// Vite build seems to be unable to recognize this injection
8+
// code from the signature-v4-crt index module.
9+
signatureV4CrtContainer.CrtSignerV4 = CrtSignerV4;
10+
crtAvailability.isCrtAvailable = true;
11+
412
import { FinalizeRequestMiddleware } from "@aws-sdk/types";
5-
import chai from "chai";
6-
import chaiAsPromised from "chai-as-promised";
13+
import { describe, expect, test as it } from "vitest";
714

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

10-
chai.use(chaiAsPromised);
11-
const { expect } = chai;
12-
1317
describe("EventBridge", () => {
14-
const client = new EventBridge({});
18+
const client = new EventBridge({
19+
region: "us-west-2",
20+
credentials: {
21+
accessKeyId: "CLIENT_TEST",
22+
secretAccessKey: "CLIENT_TEST",
23+
},
24+
});
1525
// Middleware intercept request and return it before reaching the HTTP client. It records the request and context
1626
// and return them in the Metadata.
1727
const interceptionMiddleware: FinalizeRequestMiddleware<any, any> = (next, context) => (args) => {

clients/client-eventbridge/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"rootDir": "src",
1010
"useUnknownInCatchVariables": false
1111
},
12-
"exclude": ["test/"]
12+
"exclude": ["test/", "vitest.*.ts"]
1313
}

clients/client-eventbridge/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"declarationDir": "dist-types",
77
"emitDeclarationOnly": true
88
},
9-
"exclude": ["test/**/*", "dist-types/**/*"]
9+
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

clients/client-kinesis/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo kinesis",
15-
"test:e2e": "vitest run -c vitest.config.e2e.ts",
15+
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development",
1616
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts"
1717
},
1818
"main": "./dist-cjs/index.js",

clients/client-kinesis/test/Kinesis.e2e.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { test as it, describe, expect } from "vitest";
1+
import { beforeAll, describe, expect, test as it } from "vitest";
22

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

55
describe("@aws-sdk/client-kinesis", () => {
6-
const client = new KinesisClient({});
6+
beforeAll(async () => {});
7+
8+
const client = new KinesisClient({
9+
region: "us-west-2",
10+
});
711
const ONE_SECOND = 1 * 1000;
812

913
// TODO: not working in CI

clients/client-lex-runtime-service/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo lex-runtime-service",
15-
"test": "yarn test:unit",
16-
"test:unit": "ts-mocha test/**/*.spec.ts"
15+
"test": "vitest run",
16+
"test:watch": "vitest watch"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
@@ -65,8 +65,6 @@
6565
},
6666
"devDependencies": {
6767
"@tsconfig/node16": "16.1.3",
68-
"@types/chai": "^4.2.11",
69-
"@types/mocha": "^8.0.4",
7068
"@types/node": "^16.18.96",
7169
"concurrently": "7.0.0",
7270
"downlevel-dts": "0.10.1",

clients/client-lex-runtime-service/test/LexRuntimeService.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference types="mocha" />
21
import { HttpRequest } from "@smithy/protocol-http";
32
import { SerializeMiddleware } from "@smithy/types";
4-
import { expect } from "chai";
3+
import { describe, expect, test as it } from "vitest";
54

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

@@ -16,6 +15,10 @@ describe("@aws-sdk/client-lex-runtime-service", () => {
1615
};
1716
const client = new LexRuntimeService({
1817
region: "us-west-2",
18+
credentials: {
19+
accessKeyId: "CLIENT_TEST",
20+
secretAccessKey: "CLIENT_TEST",
21+
},
1922
});
2023
client.middlewareStack.add(validator, {
2124
step: "serialize",

clients/client-lex-runtime-service/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"rootDir": "src",
1010
"useUnknownInCatchVariables": false
1111
},
12-
"exclude": ["test/"]
12+
"exclude": ["test/", "vitest.*.ts"]
1313
}

clients/client-lex-runtime-service/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"declarationDir": "dist-types",
77
"emitDeclarationOnly": true
88
},
9-
"exclude": ["test/**/*", "dist-types/**/*"]
9+
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

clients/client-mediastore-data/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo mediastore-data",
15-
"test": "yarn test:unit",
16-
"test:unit": "ts-mocha test/**/*.spec.ts"
15+
"test": "vitest run",
16+
"test:watch": "vitest watch"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
@@ -65,8 +65,6 @@
6565
},
6666
"devDependencies": {
6767
"@tsconfig/node16": "16.1.3",
68-
"@types/chai": "^4.2.11",
69-
"@types/mocha": "^8.0.4",
7068
"@types/node": "^16.18.96",
7169
"concurrently": "7.0.0",
7270
"downlevel-dts": "0.10.1",

clients/client-mediastore-data/test/MediaStoreData.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
/// <reference types="mocha" />
21
import { HttpRequest } from "@smithy/protocol-http";
32
import { SerializeMiddleware } from "@smithy/types";
4-
import { expect } from "chai";
3+
import { describe, expect, test as it } from "vitest";
54

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

@@ -16,6 +15,10 @@ describe("@aws-sdk/client-mediastore-data", () => {
1615
};
1716
const client = new MediaStoreData({
1817
region: "us-west-2",
18+
credentials: {
19+
accessKeyId: "CLIENT_TEST",
20+
secretAccessKey: "CLIENT_TEST",
21+
},
1922
});
2023
client.middlewareStack.add(validator, {
2124
step: "serialize",

clients/client-mediastore-data/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"rootDir": "src",
1010
"useUnknownInCatchVariables": false
1111
},
12-
"exclude": ["test/"]
12+
"exclude": ["test/", "vitest.*.ts"]
1313
}

clients/client-mediastore-data/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"declarationDir": "dist-types",
77
"emitDeclarationOnly": true
88
},
9-
"exclude": ["test/**/*", "dist-types/**/*"]
9+
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

clients/client-s3-control/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo s3-control",
15-
"test": "yarn test:unit",
16-
"test:unit": "ts-mocha test/**/*.spec.ts"
15+
"test": "vitest run",
16+
"test:watch": "vitest watch"
1717
},
1818
"main": "./dist-cjs/index.js",
1919
"types": "./dist-types/index.d.ts",
@@ -72,7 +72,6 @@
7272
},
7373
"devDependencies": {
7474
"@tsconfig/node16": "16.1.3",
75-
"@types/mocha": "^8.0.4",
7675
"@types/node": "^16.18.96",
7776
"concurrently": "7.0.0",
7877
"downlevel-dts": "0.10.1",

clients/client-s3-control/test/S3Control.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/// <reference types="mocha" />
21
import { FinalizeRequestMiddleware } from "@aws-sdk/types";
3-
import { expect } from "chai";
2+
import { describe, expect, test as it } from "vitest";
43

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

clients/client-s3-control/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"rootDir": "src",
1010
"useUnknownInCatchVariables": false
1111
},
12-
"exclude": ["test/"]
12+
"exclude": ["test/", "vitest.*.ts"]
1313
}

clients/client-s3-control/tsconfig.types.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"declarationDir": "dist-types",
77
"emitDeclarationOnly": true
88
},
9-
"exclude": ["test/**/*", "dist-types/**/*"]
9+
"exclude": ["test/**/*", "dist-types/**/*", "vitest.*.ts"]
1010
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.{integ,e2e,browser}.spec.ts"],
6+
include: ["**/*.spec.ts"],
7+
environment: "node",
8+
},
9+
});

clients/client-s3/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
*.tgz
88
*.log
99
package-lock.json
10-
!karma.conf.js
1110
/test/browser-build/browser-s3-bundle.js

clients/client-s3/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"generate:client": "node ../../scripts/generate-clients/single-service --solo s3",
1515
"test": "vitest run",
1616
"test:watch": "vitest watch",
17-
"test:e2e": "vitest run -c vitest.config.e2e.ts && yarn test:browser",
17+
"test:e2e": "vitest run -c vitest.config.e2e.ts --mode development && yarn test:browser",
1818
"test:e2e:watch": "vitest watch -c vitest.config.e2e.ts",
19-
"test:browser": "node ./test/browser-build/esbuild && vitest run -c vitest.config.browser.ts",
19+
"test:browser": "node ./test/browser-build/esbuild && vitest run -c vitest.config.browser.ts --mode development",
2020
"test:browser:watch": "node ./test/browser-build/esbuild && vitest watch -c vitest.config.browser.ts"
2121
},
2222
"main": "./dist-cjs/index.js",
@@ -86,8 +86,6 @@
8686
"devDependencies": {
8787
"@aws-sdk/signature-v4-crt": "*",
8888
"@tsconfig/node16": "16.1.3",
89-
"@types/chai": "^4.2.11",
90-
"@types/mocha": "^8.0.4",
9189
"@types/node": "^16.18.96",
9290
"concurrently": "7.0.0",
9391
"downlevel-dts": "0.10.1",

clients/client-s3/test/e2e/S3.browser.e2e.spec.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* This is the integration test that make sure the client can make request cross-platform-ly
3-
* in NodeJS and browsers.
4-
*/
51
import type { S3, SelectObjectContentEventStream } from "@aws-sdk/client-s3";
62
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
73
import { FetchHttpHandler } from "@smithy/fetch-http-handler";
@@ -33,7 +29,7 @@ describe("@aws-sdk/client-s3", () => {
3329
credentials: fromNodeProviderChain(),
3430
requestHandler: new FetchHttpHandler(),
3531
})
36-
) as S3;
32+
) as unknown as S3;
3733
});
3834

3935
describe("PutObject", () => {

clients/client-s3/test/e2e/S3.e2e.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "@aws-sdk/signature-v4-crt";
22

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

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

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

2321
region = process?.env?.AWS_SMOKE_TEST_REGION as string;
24-
credentials = (globalThis as any).credentials || undefined;
2522
Bucket = process?.env?.AWS_SMOKE_TEST_BUCKET as string;
2623
mrapArn = (globalThis as any)?.window?.__env__?.AWS_SMOKE_TEST_MRAP_ARN || process?.env?.AWS_SMOKE_TEST_MRAP_ARN;
2724

2825
Key = ``;
2926

3027
client = new S3({
3128
region,
32-
credentials,
3329
});
3430
});
3531

0 commit comments

Comments
 (0)