Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

76
Views
Which createReadStream am I calling here?

I'm trying to mock a call to S3 using the aws-sdk-mock package. I want to mock getObject on a bucket, so that instead of createReadStream() creating a network stream from a bucket, it creates a readable stream from a local file in my test suite.

Here's how I'm mocking the s3 call:

s3Spy = AWS.mock("S3", "getObject", {
    createReadStream: () => {
        return fs.createReadStream(testDataFile)
    }
});

Here's the line where it is used:

const stream = s3.getObject(params).createReadStream();

I can trace stream with a console.log call, and it's clearly a readable:

console.log(stream)
Readable {
  _readableState: ReadableState {
    ...
  },
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  _read: [Function (anonymous)],
  [Symbol(kCapture)]: false
}

However, if I inspect it further, it's not a file readable:

console.log(stream.path)
undefined

Which createReadStream am I calling if it's not the one in my mock? How can I write this so that I pull in the mocked data that I want to use?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I solved the problem by changing the mocking code:

s3Spy = AWS.mock("S3", "getObject", fs.createReadStream(testDataFile));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!