From 0169695ddd2b1dfdf0cf39bd0c87d56b7644a53d Mon Sep 17 00:00:00 2001 From: Jaap van Blaaderen Date: Wed, 25 Sep 2024 09:03:15 +0200 Subject: [PATCH 1/2] fix: use namespace imports instead of default imports and remove the need to enable `esModuleInterop` in tsconfig --- packages/aws-sdk-client-mock-jest/src/jestMatchers.ts | 2 +- packages/aws-sdk-client-mock/src/mockClient.ts | 6 +++--- tsconfig.json | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts b/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts index 2db6471..2ba042f 100644 --- a/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts +++ b/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-interface */ -import assert from 'assert'; +import * as assert from 'assert'; import type {MetadataBearer} from '@smithy/types'; import {AwsCommand, AwsStub} from 'aws-sdk-client-mock'; import type {SinonSpyCall} from 'sinon'; diff --git a/packages/aws-sdk-client-mock/src/mockClient.ts b/packages/aws-sdk-client-mock/src/mockClient.ts index f9388ef..6162230 100644 --- a/packages/aws-sdk-client-mock/src/mockClient.ts +++ b/packages/aws-sdk-client-mock/src/mockClient.ts @@ -1,5 +1,5 @@ import {Client, Command, MetadataBearer} from '@smithy/types'; -import sinon, {SinonSandbox, SinonStub} from 'sinon'; +import * as sinon from 'sinon'; import {isSinonStub} from './sinon'; import {AwsClientStub, AwsStub} from './awsClientStub'; @@ -12,7 +12,7 @@ import {AwsClientStub, AwsStub} from './awsClientStub'; */ export const mockClient = ( client: InstanceOrClassType>, - {sandbox}: { sandbox?: SinonSandbox } = {}, + {sandbox}: { sandbox?: sinon.SinonSandbox } = {}, ): AwsClientStub> => { const instance = isClientInstance(client) ? client : client.prototype; @@ -22,7 +22,7 @@ export const mockClient = ], Promise>; + const sendStub = sinonSandbox.stub(instance, 'send') as sinon.SinonStub<[Command], Promise>; // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return new AwsStub(instance, sendStub); diff --git a/tsconfig.json b/tsconfig.json index f74e8f8..1d28af3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,6 @@ "strict": true, "sourceMap": true, "declaration": true, - "esModuleInterop": true, "importHelpers": true, "noImplicitAny": true, "noImplicitReturns": true, From 2fafb29dff7c0a7950c53555a9ad0cb0024efe49 Mon Sep 17 00:00:00 2001 From: Jaap van Blaaderen Date: Wed, 25 Sep 2024 09:40:03 +0200 Subject: [PATCH 2/2] fix: use `assert.ok()` instead of `assert()` Ensures it plays nicely with the namespace import and ensure `pnpm test-types` succeeds --- packages/aws-sdk-client-mock-jest/src/jestMatchers.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts b/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts index 2ba042f..095ecd8 100644 --- a/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts +++ b/packages/aws-sdk-client-mock-jest/src/jestMatchers.ts @@ -275,8 +275,8 @@ const processMatch = ({ctx, mockClient, command, check, m }; message: (params: MessageFunctionParams) => string[]; }): ExpectationResult => { - assert(mockClient instanceof AwsStub, 'The actual must be a client mock instance'); - command && assert( + assert.ok(mockClient instanceof AwsStub, 'The actual must be a client mock instance'); + command && assert.ok( command && typeof command === 'function' && typeof command.name === 'string' && @@ -310,7 +310,7 @@ const processMatch = ({ctx, mockClient, command, check, m }; const ensureNoOtherArgs = (args: unknown[]): void => { - assert(args.length === 0, 'Too many matcher arguments'); + assert.ok(args.length === 0, 'Too many matcher arguments'); }; const baseMatchers: { [P in keyof AwsSdkJestMockBaseMatchers]: MatcherFunction } = { @@ -398,7 +398,7 @@ const baseMatchers: { [P in keyof AwsSdkJestMockBaseMatchers]: MatcherF ...other: unknown[] ) { ensureNoOtherArgs(other); - assert( + assert.ok( call && typeof call === 'number' && call > 0, 'Call number must be a number greater than 0', ); @@ -453,7 +453,7 @@ const baseMatchers: { [P in keyof AwsSdkJestMockBaseMatchers]: MatcherF ...other: unknown[] ) { ensureNoOtherArgs(other); - assert( + assert.ok( call && typeof call === 'number' && call > 0, 'Call number must be a number greater than 0', );