taiko icon indicating copy to clipboard operation
taiko copied to clipboard

Empty body for intercept not possible

Open RobertBeilich opened this issue 4 years ago • 5 comments

Describe the bug If not setting the body for an intercept, the intercept fails when called. There are responses without bodies, e.g. 204 No Content, so this behaviour has to be an expected one. Same applies if the body actively is set to undefined or null

To Reproduce

const { openBrowser, intercept, goto } = require('taiko');
(async () => {
  await openBrowser();
  await intercept('https://example.com', {status: 204});
  await goto('https://example.com');
})()

Error message

Uncaught The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

Expected behavior Intercept works.

Additional context

  • This bug is caused by Buffer.from(responseBodyJson) in lib/handlers/fetchHandler.js (undefined is passed to Buffer.from)

RobertBeilich avatar Oct 14 '20 14:10 RobertBeilich

@RobertBeilich would you like to send a pull request with a fix? I see that you've identified what's causing the issue.

zabil avatar Oct 15 '20 14:10 zabil

@RobertBeilich would you like to send a pull request with a fix? I see that you've identified what's causing the issue.

Yes, I'm going to tackle it.

RobertBeilich avatar Oct 16 '20 09:10 RobertBeilich

I'm asking to reopen this issue. The merged solution is not only not sufficient, it rather is arguably even more erroneous, as it now adds an empty body to all requests, instead of omitting it where necessary. I'm still investigating how to properly handle null, as the chrome fetch api is not handling it. Probably the right solution is to process it as JSON.stringify would do it and convert it to the string 'null', but I'll need to have a deeper look into it.

RobertBeilich avatar Nov 04 '20 08:11 RobertBeilich

@RobertBeilich Just circling back to see if you are still on this? No worries if you aren't this can be assigned to someone.

zabil avatar Oct 14 '21 09:10 zabil

@RobertBeilich Just circling back to see if you are still on this? No worries if you aren't this can be assigned to someone.

Ah, sry, totally forgot about that one. Will have a look at the current state of my implementation and how it fits in current master.

RobertBeilich avatar Oct 18 '21 09:10 RobertBeilich