Skip to content

Commit

Permalink
test: add spec typecheck to integration step (#6666)
Browse files Browse the repository at this point in the history
* test: add spec typecheck to integration step

* test(middleware-sdk-s3): update test tsconfig
  • Loading branch information
kuhe authored Nov 14, 2024
1 parent 361a738 commit a0be64f
Show file tree
Hide file tree
Showing 34 changed files with 85 additions and 51 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ test-unit: build-s3-browser-bundle
yarn g:vitest run -c vitest.config.clients.unit.ts
npx jest -c jest.config.js

# typecheck for test code.
test-types:
npx tsc -p tsconfig.test.json

test-protocols: build-s3-browser-bundle
yarn g:vitest run -c vitest.config.protocols.integ.ts

Expand All @@ -26,6 +30,7 @@ test-integration: build-s3-browser-bundle
yarn g:vitest run -c vitest.config.integ.ts
npx jest -c jest.config.integ.js
make test-protocols;
make test-types;

test-e2e: build-s3-browser-bundle
yarn g:vitest run -c vitest.config.e2e.ts --retry=4
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/test/e2e/S3.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe("@aws-sdk/client-s3", () => {
const body = createBuffer("1MB");
let bodyChecksum = "";

const bodyChecksumReader = (next) => async (args) => {
const bodyChecksumReader = (next: any) => async (args: any) => {
const checksumValue = args.request.headers["x-amz-checksum-crc32"];
if (checksumValue) {
bodyChecksum = checksumValue;
Expand Down
2 changes: 1 addition & 1 deletion clients/client-s3/test/unit/flexibleChecksums.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("Flexible Checksums", () => {
expect(headers["transfer-encoding"]).to.equal("chunked");
expect(headers["x-amz-content-sha256"]).to.equal("STREAMING-UNSIGNED-PAYLOAD-TRAILER");
expect(headers["x-amz-trailer"]).to.equal(checksumHeader);
body.on("data", (data) => {
body.on("data", (data: any) => {
const stringValue = data.toString();
if (stringValue.startsWith(checksumHeader)) {
const receivedChecksum = stringValue.replace("\r\n", "").split(":")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe(resolveSSOCredentials.name, () => {

it("creates SSO client with provided region, if client is not passed", async () => {
const mockCustomSsoSend = vi.fn().mockResolvedValue({ roleCredentials: mockCreds });
vi.mocked(SSOClient).mockReturnValue({ send: mockCustomSsoSend });
vi.mocked(SSOClient as any).mockReturnValue({ send: mockCustomSsoSend });

await resolveSSOCredentials({ ...mockOptions, ssoClient: undefined });
expect(mockCustomSsoSend).toHaveBeenCalledTimes(1);
Expand All @@ -176,7 +176,7 @@ describe(resolveSSOCredentials.name, () => {

it("creates SSO client with provided region, if client is not passed, and includes accountId", async () => {
const mockCustomSsoSend = vi.fn().mockResolvedValue({ roleCredentials: mockCreds });
vi.mocked(SSOClient).mockReturnValue({ send: mockCustomSsoSend });
vi.mocked(SSOClient as any).mockReturnValue({ send: mockCustomSsoSend });

const result = await resolveSSOCredentials({ ...mockOptions, ssoClient: undefined });
expect(result).toHaveProperty("accountId", mockOptions.ssoAccountId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("fromTemporaryCredentials", () => {
secretAccessKey: "SECRET_ACCESS_KEY",
sessionToken: "SESSION_TOKEN",
});
expect(vi.mocked(STSClient)).toHaveBeenCalledWith({
expect(vi.mocked(STSClient as any)).toHaveBeenCalledWith({
credentials: masterCredentials,
region,
});
Expand All @@ -86,7 +86,7 @@ describe("fromTemporaryCredentials", () => {
clientPlugins: [plugin],
});
await provider();
expect(vi.mocked(STSClient)).toHaveBeenCalledWith({
expect(vi.mocked(STSClient as any)).toHaveBeenCalledWith({
credentials: masterCredentials,
});
expect(mockUsePlugin).toHaveBeenCalledTimes(1);
Expand All @@ -101,7 +101,7 @@ describe("fromTemporaryCredentials", () => {
},
});
await provider();
expect(vi.mocked(STSClient)).toHaveBeenCalledWith({});
expect(vi.mocked(STSClient as any)).toHaveBeenCalledWith({});
});

it("should create a role session name if none provided", async () => {
Expand Down Expand Up @@ -140,22 +140,22 @@ describe("fromTemporaryCredentials", () => {
expect(credentials.accessKeyId).toBe("access_id_from_third");
// Creates STS Client with right master credentials and assume role with
// expected role arn.
expect(vi.mocked(STSClient).mock.results.length).toBe(3);
const outmostClient = vi.mocked(STSClient).mock.results[0].value;
expect(vi.mocked(STSClient as any).mock.results.length).toBe(3);
const outmostClient = vi.mocked(STSClient as any).mock.results[0].value;
expect(outmostClient.config.credentials).toEqual(expect.objectContaining({ accessKeyId: "access_id_from_second" }));
expect((outmostClient.send as any).mock.calls.length).toBe(1);
expect((outmostClient.send as any).mock.calls[0][0].input).toEqual(
expect.objectContaining({ RoleArn: roleArnOf("third") })
);

const middleClient = vi.mocked(STSClient).mock.results[1].value;
const middleClient = vi.mocked(STSClient as any).mock.results[1].value;
expect(middleClient.config.credentials).toEqual(expect.objectContaining({ accessKeyId: "access_id_from_first" }));
expect((middleClient.send as any).mock.calls.length).toBe(1);
expect((middleClient.send as any).mock.calls[0][0].input).toEqual(
expect.objectContaining({ RoleArn: roleArnOf("second") })
);

const innermostClient = vi.mocked(STSClient).mock.results[2].value;
const innermostClient = vi.mocked(STSClient as any).mock.results[2].value;
expect(innermostClient.config.credentials).toEqual(undefined);
expect((innermostClient.send as any).mock.calls.length).toBe(1);
expect((innermostClient.send as any).mock.calls[0][0].input).toEqual(
Expand All @@ -169,7 +169,7 @@ describe("fromTemporaryCredentials", () => {

// Should not create extra clients if credentials is still valid
await provider();
expect(vi.mocked(STSClient).mock.results.length).toBe(3);
expect(vi.mocked(STSClient as any).mock.results.length).toBe(3);
});

it("should support assuming a role with multi-factor authentication", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe(EventStreamPayloadHandler.name, () => {

beforeEach(() => {
(EventSigningStream as unknown as any).mockImplementation(() => new PassThrough());
vi.mocked(EventStreamCodec).mockImplementation(() => {});
vi.mocked(EventStreamCodec).mockImplementation((() => {}) as any);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse as parseArn } from "@aws-sdk/util-arn-parser";
import { describe, expect, expect, test as it } from "vitest";
import { describe, expect, test as it } from "vitest";

import { bucketHostname } from "./bucketHostname";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(getEndpointDiscoveryPlugin.name, () => {

it(`applyToStack function adds endpoint discovery middleware`, () => {
const middlewareReturn = {};
vi.mocked(endpointDiscoveryMiddleware).mockReturnValueOnce(middlewareReturn);
vi.mocked(endpointDiscoveryMiddleware).mockReturnValueOnce(middlewareReturn as any);

// @ts-ignore
const plugin = getEndpointDiscoveryPlugin(pluginConfig, middlewareConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vi.mock("@smithy/util-middleware");

describe(resolveFlexibleChecksumsConfig.name, () => {
beforeEach(() => {
vi.mocked(normalizeProvider).mockImplementation((input) => input);
vi.mocked(normalizeProvider).mockImplementation((input) => input as any);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ describe(validateChecksumFromResponse.name, () => {

beforeEach(() => {
vi.mocked(getChecksumLocationName).mockImplementation((algorithm) => algorithm);
vi.mocked(getChecksumAlgorithmListForResponse).mockImplementation((responseAlgorithms) => responseAlgorithms);
vi.mocked(getChecksumAlgorithmListForResponse).mockImplementation(
(responseAlgorithms) => responseAlgorithms as any
);
vi.mocked(selectChecksumAlgorithmFunction).mockReturnValue(mockChecksumAlgorithmFn);
vi.mocked(getChecksum).mockResolvedValue(mockChecksum);
vi.mocked(createChecksumStream).mockReturnValue(mockBodyStream);
vi.mocked(createChecksumStream).mockReturnValue(mockBodyStream as any);
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-host-header/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRequest } from "@smithy/protocol-http";
import { beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { beforeEach, describe, expect, test as it, vi } from "vitest";

import { hostHeaderMiddleware } from "./index";
describe("hostHeaderMiddleware", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { S3 } from "@aws-sdk/client-s3";
import { describe, expect, expect, test as it } from "vitest";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RDS } from "@aws-sdk/client-rds";
import { describe, expect, expect, test as it } from "vitest";
import { describe, expect, test as it } from "vitest";

import { TestHttpHandler } from "../../../private/aws-util-test/src";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Route53 } from "@aws-sdk/client-route-53";
import { XMLParser } from "fast-xml-parser";
import { describe, expect, expect, test as it } from "vitest";
import { describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { constructStack } from "@smithy/middleware-stack";
import { HttpRequest } from "@smithy/protocol-http";
import { Provider, RegionInfo } from "@smithy/types";
import { beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { beforeEach, describe, expect, test as it, vi } from "vitest";

import { S3ControlResolvedConfig } from "../configurations";
import { getProcessArnablesPlugin } from "./getProcessArnablesPlugin";
Expand Down
3 changes: 2 additions & 1 deletion packages/middleware-sdk-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "yarn g:vitest run",
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
"test:types": "tsc -p tsconfig.test.json",
"test:integration": "yarn g:vitest run -c vitest.config.integ.ts && yarn test:types",
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.ts --mode development",
"extract:docs": "api-extractor run --local",
"test:watch": "yarn g:vitest watch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { checkContentLengthHeader } from "./check-content-length-header";
describe("checkContentLengthHeaderMiddleware", () => {
const mockNextHandler = vi.fn();

let spy: vi.SpyInstance;
let spy: any;

beforeEach(() => {
spy = vi.spyOn(console, "warn");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { S3 } from "@aws-sdk/client-s3";
import { describe, expect, expect, test as it, vi } from "vitest";
import { describe, expect, test as it, vi } from "vitest";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async function createClientAndRecorder() {
}

const commandName = context.commandName + s3ExpressSuffix;
const input = args.input;
const input = args.input as any;
const commandRecorder = (recorder.calls[commandName] = recorder.calls[commandName] ?? {});
commandRecorder[input["Bucket"] ?? "-"] |= 0;
commandRecorder[input["Bucket"] ?? "-"]++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpRequest, HttpResponse } from "@smithy/protocol-http";
import { toUtf8 } from "@smithy/util-utf8";
import { Readable } from "stream";
import { beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { beforeEach, describe, expect, test as it, vi } from "vitest";

import { throw200ExceptionsMiddleware } from "./throw-200-exceptions";

Expand Down
11 changes: 11 additions & 0 deletions packages/middleware-sdk-s3/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"skipLibCheck": true,
"noEmit": true
},
"extends": "../../tsconfig.cjs.json",
"include": ["src/**/s3-type-transforms.integ.spec.ts"],
"exclude": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpHandler, HttpResponse } from "@smithy/protocol-http";
import type { AwsCredentialIdentity } from "@smithy/types";
import crypto from "crypto";
import { Readable } from "stream";
import { beforeEach, describe, expect, expect, test as it } from "vitest";
import { beforeEach, describe, expect, test as it } from "vitest";

import { requireRequestsFrom } from "../../../private/aws-util-test/src";

Expand Down
6 changes: 3 additions & 3 deletions packages/middleware-signing/src/awsAuthMiddleware.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRequest } from "@smithy/protocol-http";
import { FinalizeHandler, RequestSigner } from "@smithy/types";
import { RequestSigner } from "@smithy/types";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";

import { AwsAuthResolvedConfig } from "./awsAuthConfiguration";
Expand All @@ -11,11 +11,11 @@ vi.mock("./utils/getUpdatedSystemClockOffset");
vi.mock("./utils/getSkewCorrectedDate");

describe(awsAuthMiddleware.name, () => {
let mockSignFn: vi.Mock<any, any>;
let mockSignFn: any;
let mockSigner: () => Promise<RequestSigner>;
let mockOptions: AwsAuthResolvedConfig;

const mockNext: vi.MockedFunction<FinalizeHandler<any, any>> = vi.fn();
const mockNext: any = vi.fn();
const mockSystemClockOffset = 100;
const mockUpdatedSystemClockOffset = 500;
const mockSigningHandlerArgs = {
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-token/src/getTokenPlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(getTokenPlugin.name, () => {

it("applyToStack adds tokenMiddleware", () => {
const middlewareReturn = {};
vi.mocked(tokenMiddleware).mockReturnValueOnce(middlewareReturn);
vi.mocked(tokenMiddleware).mockReturnValueOnce(middlewareReturn as any);

// @ts-ignore
const plugin = getTokenPlugin(pluginConfig);
Expand Down
6 changes: 3 additions & 3 deletions packages/middleware-token/src/normalizeTokenProvider.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memoize } from "@smithy/property-provider";
import { normalizeProvider } from "@smithy/util-middleware";
import { afterEach, beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";

import { normalizeTokenProvider } from "./normalizeTokenProvider";

Expand Down Expand Up @@ -73,13 +73,13 @@ describe(normalizeTokenProvider.name, () => {
});

it("returns true if expiration is not defined", () => {
const memoizeRefreshFn = vi.mocked(memoize).mock.calls[0][2];
const memoizeRefreshFn = vi.mocked(memoize).mock.calls[0][2]!;
const expiration = Date.now();
expect(memoizeRefreshFn({ expiration })).toEqual(true);
});

it("returns false if expiration is not defined", () => {
const memoizeRefreshFn = vi.mocked(memoize).mock.calls[0][2];
const memoizeRefreshFn = vi.mocked(memoize).mock.calls[0][2]!;
expect(memoizeRefreshFn({})).toEqual(false);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-user-agent/src/check-features.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(checkFeatures.name, () => {
identity: {
accountId: "123456789012",
$source: {},
},
} as any,
},
},
} as AwsHandlerExecutionContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setPartitionInfo, useDefaultPartitionInfo } from "@aws-sdk/util-endpoints";
import { HttpRequest } from "@smithy/protocol-http";
import { UserAgentPair } from "@smithy/types";
import { afterEach, beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";

import { USER_AGENT, X_AMZ_USER_AGENT } from "./constants";
import { userAgentMiddleware } from "./user-agent-middleware";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventStreamCodec } from "@smithy/eventstream-codec";
import { Decoder, Encoder, FinalizeHandler, FinalizeHandlerArguments, HttpRequest, MessageSigner } from "@smithy/types";
import { afterEach, beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
import { ReadableStream, TransformStream } from "web-streams-polyfill";

import { EventStreamPayloadHandler } from "./EventStreamPayloadHandler";
Expand All @@ -21,7 +21,7 @@ describe(EventStreamPayloadHandler.name, () => {
beforeEach(() => {
window.TransformStream = TransformStream;
(getEventSigningTransformStream as unknown as any).mockImplementation(() => new TransformStream());
vi.mocked(EventStreamCodec).mockImplementation(() => {});
vi.mocked(EventStreamCodec).mockImplementation((() => {}) as any);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FetchHttpHandler } from "@smithy/fetch-http-handler";
import { HttpRequest } from "@smithy/protocol-http";
import { WebSocket } from "mock-socket";
import { PassThrough } from "stream";
import { afterEach, beforeEach, describe, expect, expect, test as it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
import WS from "vitest-websocket-mock";

import { WebSocketFetchHandler } from "./websocket-fetch-handler";
Expand Down Expand Up @@ -139,7 +139,7 @@ describe(WebSocketFetchHandler.name, () => {
expect(err.$metadata).toBeDefined();
expect(err.$metadata.httpStatusCode >= 500).toBe(true);
expect(
((global as any).setTimeout as any).mock.calls.filter((args) => {
((global as any).setTimeout as any).mock.calls.filter((args: any) => {
//find the 'setTimeout' call from the websocket handler
return args[0].toString().indexOf("$metadata") >= 0;
})[0][1]
Expand Down
4 changes: 2 additions & 2 deletions packages/token-providers/src/fromSso.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe(fromSso.name, () => {

describe("throws validation error", () => {
it("when profile is not found", async () => {
vi.mocked(parseKnownFiles).mockReturnValue({});
vi.mocked(parseKnownFiles as any).mockReturnValue({});
const expectedError = new TokenProviderError(
`Profile '${mockProfileName}' could not be found in shared credentials file.`,
false
Expand All @@ -84,7 +84,7 @@ describe(fromSso.name, () => {

it("when sso_session is not defined for profile", async () => {
const { sso_session, ...mockSsoProfileWithoutSsoSession } = mockSsoProfile;
vi.mocked(parseKnownFiles).mockReturnValue({ [mockProfileName]: mockSsoProfileWithoutSsoSession });
vi.mocked(parseKnownFiles as any).mockReturnValue({ [mockProfileName]: mockSsoProfileWithoutSsoSession });
const expectedError = new TokenProviderError(
`Profile '${mockProfileName}' is missing required property 'sso_session'.`
);
Expand Down
Loading

0 comments on commit a0be64f

Please sign in to comment.