diff --git a/Makefile b/Makefile index 1dc19677d86b2..78699b660f018 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,27 @@ login: sync: make -f Makefile.private.mk sync +test-unit: build-s3-browser-bundle + npx vitest run -c vitest.config.ts + npx vitest run -c vitest.config.browser.ts + npx vitest run -c vitest.config.clients.unit.ts + npx jest -c jest.config.js + +test-protocols: build-s3-browser-bundle + npx vitest run -c vitest.config.protocols.integ.ts + +test-integration: build-s3-browser-bundle + npx vitest run -c vitest.config.integ.ts + npx jest -c jest.config.integ.js + make test-protocols; + +test-e2e: build-s3-browser-bundle + npx vitest run -c vitest.config.e2e.ts + npx vitest run -c vitest.config.browser.e2e.ts + +build-s3-browser-bundle: + node ./clients/client-s3/test/browser-build/esbuild + # removes nested node_modules folders clean-nested: rm -rf ./lib/*/node_modules @@ -55,9 +76,9 @@ tpk: npx turbo run build --filter='./packages/*' # Clears the Turborepo local build cache -turbo-clean: +turbo-clean: @read -p "Are you sure you want to delete your local cache? [y/N]: " ans && [ $${ans:-N} = y ] - @echo "\nDeleted cache folders: \n--------" + @echo "\nDeleted cache folders: \n--------" @find . -name '.turbo' -type d -prune -print -exec rm -rf '{}' + && echo '\n' server-protocols: diff --git a/clients/client-sts/test/defaultRoleAssumers.spec.ts b/clients/client-sts/test/defaultRoleAssumers.spec.ts index fce6dde584b2c..9daea2dc23fcc 100644 --- a/clients/client-sts/test/defaultRoleAssumers.spec.ts +++ b/clients/client-sts/test/defaultRoleAssumers.spec.ts @@ -124,7 +124,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should use the STS client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumer = getDefaultRoleAssumer({ @@ -152,7 +158,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should use the parent client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumer = getDefaultRoleAssumer({ @@ -177,7 +189,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should not pass through an Http2 requestHandler", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttp2Handler(); const roleAssumer = getDefaultRoleAssumer({ @@ -250,7 +268,13 @@ describe("getDefaultRoleAssumerWithWebIdentity", () => { }); it("should use the STS client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumerWithWebIdentity = getDefaultRoleAssumerWithWebIdentity({ diff --git a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.spec.ts b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.spec.ts index 34acdcf8a35bb..c3a96fec9bb90 100644 --- a/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.spec.ts +++ b/codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/sts-client-defaultRoleAssumers.spec.ts @@ -122,7 +122,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should use the STS client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumer = getDefaultRoleAssumer({ @@ -150,7 +156,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should use the parent client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumer = getDefaultRoleAssumer({ @@ -175,7 +187,13 @@ describe("getDefaultRoleAssumer", () => { }); it("should not pass through an Http2 requestHandler", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttp2Handler(); const roleAssumer = getDefaultRoleAssumer({ @@ -248,7 +266,13 @@ describe("getDefaultRoleAssumerWithWebIdentity", () => { }); it("should use the STS client config", async () => { - const logger = console; + const logger = { + trace() {}, + debug() {}, + info() {}, + warn() {}, + error() {}, + }; const region = "some-region"; const handler = new NodeHttpHandler(); const roleAssumerWithWebIdentity = getDefaultRoleAssumerWithWebIdentity({ diff --git a/jest.config.e2e.js b/jest.config.e2e.js index b6a9d34fddd6d..fe2d85868be3d 100644 --- a/jest.config.e2e.js +++ b/jest.config.e2e.js @@ -6,9 +6,9 @@ */ module.exports = { projects: [ - "/clients/*/jest.config.e2e.js", + // "/clients/*/jest.config.e2e.js", // "/lib/*/jest.config.integ.js", - "/packages/*/jest.config.e2e.js", + // "/packages/*/jest.config.e2e.js", // "/private/*/jest.config.e2e.js", ], }; diff --git a/jest.config.integ.js b/jest.config.integ.js index bffc1b32d78db..bfa647e159a30 100644 --- a/jest.config.integ.js +++ b/jest.config.integ.js @@ -12,6 +12,6 @@ module.exports = { // "/clients/*/jest.config.integ.js", // "/lib/*/jest.config.integ.js", "/packages/*/jest.config.integ.js", - "/private/*/jest.config.integ.js", + // "/private/*/jest.config.integ.js", ], }; diff --git a/package.json b/package.json index dc373fb2cd588..b0460b8869ab5 100644 --- a/package.json +++ b/package.json @@ -34,18 +34,18 @@ "local-publish": "node ./scripts/verdaccio-publish/index.js", "test:all": "yarn build:all && jest --passWithNoTests && lerna run test --scope '@aws-sdk/{fetch-http-handler,hash-blob-browser}' && yarn test:versions && yarn test:integration", "test:ci": "lerna run test --since origin/main", - "test:e2e": "node ./scripts/turbo test:e2e --env-mode=loose && node ./tests/canary/canary", + "test:e2e": "make test-e2e && node ./tests/canary/canary", "test:e2e:legacy": "cucumber-js --fail-fast", "test:e2e:legacy:preview": "./tests/e2e-legacy/preview.mjs", "test:e2e:legacy:since:release": "./tests/e2e-legacy/since-release.mjs", "test:functional": "jest --passWithNoTests --config tests/functional/jest.config.js && lerna run test --scope \"@aws-sdk/client-*\"", - "test:integration": "node ./scripts/turbo test:integration", + "test:integration": "make test-integration", "test:integration:legacy": "yarn test:e2e:legacy", "test:integration:legacy:since:release": "yarn test:e2e:legacy:since:release", "test:protocols": "yarn build:protocols && lerna run test --scope '@aws-sdk/aws-protocoltests-*'", "test:server-protocols": "yarn build:server-protocols && lerna run test --scope '@aws-sdk/*-server'", "test:size": "cd scripts/benchmark-size/runner && yarn && ts-node ./cli.ts", - "test:unit": "node ./scripts/turbo test", + "test:unit": "make test-unit", "test:versions": "jest --config tests/versions/jest.config.js tests/versions/index.spec.ts", "update:versions:default": "node --es-module-specifier-resolution=node ./scripts/update-versions/default.mjs", "update:versions:current": "node --es-module-specifier-resolution=node ./scripts/update-versions/current.mjs" diff --git a/vitest.config.browser.e2e.ts b/vitest.config.browser.e2e.ts new file mode 100644 index 0000000000000..4dccbddcb87b1 --- /dev/null +++ b/vitest.config.browser.e2e.ts @@ -0,0 +1,9 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*/node_modules/**/*.spec.ts"], + include: ["**/*.browser.e2e.spec.ts"], + environment: "happy-dom", + }, +}); diff --git a/vitest.config.browser.ts b/vitest.config.browser.ts new file mode 100644 index 0000000000000..35b08b23357dd --- /dev/null +++ b/vitest.config.browser.ts @@ -0,0 +1,17 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*/node_modules/**/*.spec.ts"], + include: [ + "packages/util-user-agent-browser/src/index.spec.ts", + "packages/util-user-agent-browser/src/index.native.spec.ts", + "packages/credential-provider-cognito-identity/src/localStorage-inmemoryStorage.spec.ts", + "packages/body-checksum-browser/src/index.spec.ts", + "packages/middleware-websocket/src/get-event-signing-stream.spec.ts", + "packages/middleware-websocket/src/EventStreamPayloadHandler.spec.ts", + "packages/credential-provider-cognito-identity/src/localStorage.spec.ts", + ], + environment: "happy-dom", + }, +}); diff --git a/vitest.config.clients.unit.ts b/vitest.config.clients.unit.ts new file mode 100644 index 0000000000000..0bc7178c18c55 --- /dev/null +++ b/vitest.config.clients.unit.ts @@ -0,0 +1,9 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: ["**/*/node_modules/**/*.spec.ts", "**/*.{integ,e2e,browser}.spec.ts"], + include: ["clients/client-*/**/*.spec.ts"], + environment: "node", + }, +}); diff --git a/vitest.config.e2e.ts b/vitest.config.e2e.ts index d035dcc4e5078..5faa7bfd46696 100644 --- a/vitest.config.e2e.ts +++ b/vitest.config.e2e.ts @@ -2,8 +2,8 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - exclude: ["node_modules", "**/*.browser.e2e.spec.ts"], - include: ["**/*.e2e.spec.ts"], + exclude: ["**/*/node_modules/**/*.spec.ts", "**/*.browser.e2e.spec.ts"], + include: ["clients/**/*.e2e.spec.ts", "lib/**/*.e2e.spec.ts", "packages/**/*.e2e.spec.ts"], environment: "node", }, }); diff --git a/vitest.config.integ.ts b/vitest.config.integ.ts index b25e8e1dcb00b..bc69bdc841f4e 100644 --- a/vitest.config.integ.ts +++ b/vitest.config.integ.ts @@ -2,7 +2,12 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - exclude: ["node_modules", "**/*.{e2e,browser}.spec.ts"], + exclude: [ + "**/*/node_modules/**/*.spec.ts", + "**/*.{e2e,browser}.spec.ts", + "packages/credential-providers/src/fromSSO.integ.spec.ts", + "packages/credential-provider-node/src/credential-provider-node.integ.spec.ts", + ], include: ["{clients,lib,packages,private}/**/*.integ.spec.ts"], environment: "node", }, diff --git a/vitest.config.protocols.integ.ts b/vitest.config.protocols.integ.ts new file mode 100644 index 0000000000000..ac64ef81051ee --- /dev/null +++ b/vitest.config.protocols.integ.ts @@ -0,0 +1,15 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + exclude: [ + "**/*/node_modules/**/*.spec.ts", + "**/*.{integ,e2e,browser}.spec.ts", + "private/aws-restjson-server/**/*.spec.ts", + "private/aws-restjson-validation-server/**/*.spec.ts", + ], + include: ["private/**/*.spec.ts"], + environment: "node", + globals: true, + }, +}); diff --git a/vitest.config.ts b/vitest.config.ts index 22114730664a9..659e4b54ced3f 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,15 +1,41 @@ import { defineConfig } from "vitest/config"; +/** + * AWS SDK for JavaScript test classifications: + * + * Unit tests are test scenarios that exercise a single functionality. + * Ideally, all modules other than the one being tested should be mocked. + * However, pragmiatically speaking this isn't always the case. + * Unit tests never communicate with AWS services. + * + * Integration tests involve minimal mocking and test multiple modules + * in concert. The test should use the public interfaces of our modules. + * Integration tests never communicate with AWS services. + * + * E2E tests use only the public interfaces of our code and do + * communicate with AWS services. No mocking is done for E2E tests. + * The tests run with cucumber-js are + * now considered E2E tests in this classification system. + * + * Browser tests are a separate category, require alternate configuration, + * and may be classified as unit or e2e tests. + */ export default defineConfig({ test: { exclude: [ - "node_modules", + "**/*/node_modules/**/*.spec.ts", "**/*.{integ,e2e,browser}.spec.ts", - "private/aws-restjson-server/**/*.spec.ts", - "private/aws-restjson-validation-server/**/*.spec.ts", + "packages/signature-v4-crt/**/*.spec.ts", + "packages/types/**/*.ts", + "packages/util-user-agent-browser/src/index.spec.ts", + "packages/util-user-agent-browser/src/index.native.spec.ts", + "packages/credential-provider-cognito-identity/src/localStorage-inmemoryStorage.spec.ts", + "packages/body-checksum-browser/src/index.spec.ts", + "packages/middleware-websocket/src/get-event-signing-stream.spec.ts", + "packages/middleware-websocket/src/EventStreamPayloadHandler.spec.ts", + "packages/credential-provider-cognito-identity/src/localStorage.spec.ts", ], - include: ["clients/client-*/**/*.spec.ts", "lib/**/*.spec.ts", "packages/**/*.spec.ts", "private/**/*.spec.ts"], + include: ["lib/**/*.spec.ts", "packages/**/*.spec.ts"], environment: "node", - globals: true, }, });