Skip to content

Unable to mock a file stream in S3 Client Mock #247

@dreessan

Description

@dreessan

Checklist

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

Bug description

Attached sample does not work

  1. I have also tried several permutations on Readable and fs.ReadStream
  2. Q is unable to help. Q seems to think that my code ought to work.

Here is the error it produces:

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 'Readable & SdkStreamMixin'.
      Type 'ReadableStream & SdkStreamMixin' is missing the following properties from type 'Readable': readable, readableEncoding, readableEnded, readableFlowing, and 33 more.ts(2322)
(property) Body?: StreamingBlobPayloadOutputTypes | undefined

Reproduction

import { mockClient } from "aws-sdk-client-mock";
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { sdkStreamMixin } from "@smithy/util-stream";
import fs from "node:fs";
import { Readable } from "node:stream";

const s3ClientMock = mockClient(S3Client);

const trainingData = fs.createReadStream(
  __dirname + "path/to/file.csv",
  "utf8"
);
describe("oversampleTraining", () => {
  beforeEach(() => {
    s3ClientMock.reset();
  });

  it("oversamples the training data", () => {
    s3ClientMock.on(GetObjectCommand).resolves({
      Body: sdkStreamMixin(Readable.from(trainingData)),
    });
  });
});

Environment

  • Node version: using bb app -v :: 8.19.4
  • Testing lib and version: "jest": "^29.4.3",
  • Typescript version: "~4.7.4"
  • AWS SDK v3 Client mock version: "^3.1.0"
  • AWS JS SDK libs and versions:
    • "@aws-sdk/client-s3": "^3.515.0",

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions