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

"Not Assignable to type" error trying to mock S3 GetObject for Binary File. #227

Open
1 task done
gbbayareametro opened this issue Jun 18, 2024 · 1 comment
Open
1 task done
Labels
bug Something isn't working waiting for reply

Comments

@gbbayareametro
Copy link

Checklist

  • I have read Caveats documentation and didn't find a solution for this problem there.

Bug description

Mocking getting an excel workbook from an S3 bucket. The functionality I'm testing is going to be in a NodeJS lambda.

Here's the code I'm testing:

export const getFile = async (
  bucket: string,
  object: string
): Promise<SdkStream<IncomingMessage>> => {
  const logger = instance;
  const client = new S3Client({}) as NodeJsClient<S3Client>;

  const body: SdkStream<IncomingMessage> = (
    await client.send(new GetObjectCommand({ Key: "", Bucket: "" }))
  ).Body!;
  return body;
};

Here's my test (No real tests yet because I'm blocked trying to get the mock going):

 test("It gets the file successfully from S3", async () => {
    const readStream = createReadStream("./mockListings.xslx");
    const stream = sdkStreamMixin(readStream);
    const s3ClientMock = mockClient(S3Client);
    s3ClientMock.on(GetObjectCommand).resolves({ Body: stream });
  });

I'm getting this error:

Type 'SdkStream<ReadableStream | Blob> | SdkStream<Readable>' is not assignable to type 'StreamingBlobPayloadOutputTypes | undefined'.
  Type 'ReadableStream & SdkStreamMixin' is not assignable to type 'StreamingBlobPayloadOutputTypes | undefined'.
    Type 'ReadableStream & SdkStreamMixin' is not assignable to type 'BrowserRuntimeStreamingBlobPayloadOutputTypes'.
      Type 'ReadableStream & SdkStreamMixin' is missing the following properties from type 'Blob': size, type, arrayBuffer, slice, and 2 more.

Here's the output of 'npm ls' indicating that I only have the latest version of @smithy/types installed:

@aws-sdk/client-s3@3.598.0
│ ├─┬ @aws-sdk/client-sso-oidc@3.598.0
│ │ ├── @smithy/types@3.1.0 deduped
│ │ └─┬ @smithy/util-middleware@3.0.1
│ │   └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/client-sts@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/core@3.598.0
│ │ ├─┬ @smithy/signature-v4@3.1.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/credential-provider-node@3.598.0
│ │ ├─┬ @aws-sdk/credential-provider-env@3.598.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @aws-sdk/credential-provider-http@3.598.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @aws-sdk/credential-provider-ini@3.598.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @aws-sdk/credential-provider-process@3.598.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @aws-sdk/credential-provider-sso@3.598.0
│ │ │ ├─┬ @aws-sdk/client-sso@3.598.0
│ │ │ │ └── @smithy/types@3.1.0 deduped
│ │ │ ├─┬ @aws-sdk/token-providers@3.598.0
│ │ │ │ └── @smithy/types@3.1.0 deduped
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @aws-sdk/credential-provider-web-identity@3.598.0
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @smithy/credential-provider-imds@3.1.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @smithy/property-provider@3.1.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ ├─┬ @smithy/shared-ini-file-loader@3.1.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-bucket-endpoint@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-expect-continue@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-flexible-checksums@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-host-header@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-location-constraint@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-logger@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-recursion-detection@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-sdk-s3@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-signing@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-ssec@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/middleware-user-agent@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/region-config-resolver@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/signature-v4-multi-region@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/types@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/util-endpoints@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/util-user-agent-browser@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/util-user-agent-node@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @aws-sdk/xml-builder@3.598.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/config-resolver@3.0.2
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/core@2.2.2
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/eventstream-serde-browser@3.0.2
│ │ ├─┬ @smithy/eventstream-serde-universal@3.0.2
│ │ │ ├─┬ @smithy/eventstream-codec@3.1.0
│ │ │ │ └── @smithy/types@3.1.0 deduped
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/eventstream-serde-config-resolver@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/eventstream-serde-node@3.0.2
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/fetch-http-handler@3.0.3
│ │ ├─┬ @smithy/querystring-builder@3.0.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/hash-blob-browser@3.1.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/hash-node@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/hash-stream-node@3.1.0
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/invalid-dependency@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/md5-js@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/middleware-content-length@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/middleware-endpoint@3.0.2
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/middleware-retry@3.0.5
│ │ ├─┬ @smithy/service-error-classification@3.0.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/middleware-serde@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/middleware-stack@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/node-config-provider@3.1.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/node-http-handler@3.0.1
│ │ ├─┬ @smithy/abort-controller@3.0.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/protocol-http@4.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/smithy-client@3.1.3
│ │ └── @smithy/types@3.1.0 deduped
│ ├── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/url-parser@3.0.1
│ │ ├─┬ @smithy/querystring-parser@3.0.1
│ │ │ └── @smithy/types@3.1.0 deduped
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/util-defaults-mode-browser@3.0.5
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/util-defaults-mode-node@3.0.5
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/util-endpoints@2.0.2
│ │ └── @smithy/types@3.1.0 deduped
│ ├─┬ @smithy/util-retry@3.0.1
│ │ └── @smithy/types@3.1.0 deduped
│ └─┬ @smithy/util-waiter@3.0.1
│   └── @smithy/types@3.1.0 deduped
├── @smithy/types@3.1.0
└─┬ @smithy/util-stream@3.0.3
  └── @smithy/types@3.1.0 deduped

Any help resolving the error would be appreciated.

Reproduction

Environment

  • Node version:
  • Testing lib and version:
  • Typescript version:
  • AWS SDK v3 Client mock version:
  • AWS JS SDK libs and versions:
@m-radzikowski
Copy link
Owner

I don't see any type errors with your snippets and latest dependency versions:

    "@aws-sdk/client-s3": "3.654.0",
    "@smithy/util-stream": "3.1.8",
    "@smithy/types": "3.4.2",
    "aws-sdk-client-mock": "4.0.1",
    "typescript": "5.6.2"

Please update dependencies and if problem remains, please create a small repo with proper reproduction. It should be possible to run:

npm install
tsc

to see the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for reply
Projects
None yet
Development

No branches or pull requests

2 participants