Skip to content

Conversation

fornfrey
Copy link

@fornfrey fornfrey commented Aug 4, 2025

From k6 docs:

Blob is not supported or implemented

This PR replaces usages of Blob with k6-compatible ArrayBuffer and improves the request body generation logic.

Comment on lines +133 to 134
} else if (body.contentType === 'application/json') {
fetchBodyOption = `JSON.stringify(${body.implementation})`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Json serialization should be used only for application/json content type.

@fornfrey fornfrey marked this pull request as ready for review August 4, 2025 09:15
@fornfrey fornfrey requested a review from a team as a code owner August 4, 2025 09:15
Comment on lines +62 to +67
const newFileContent = fileContent.replaceAll(
/(^|\W)Blob(?!\w)/g,
'$1ArrayBuffer'
)

fs.writeFileSync(filePath, newFileContent)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have any tests for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will actually replace "Blob" string from the documentation or other string occurrences as well - "foo Blob bar" will be replaced too.
Let not use regex replace for this and try to use ArrayBuffer, I will have to check with orval and code if that is possible thought

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Blob type is hardcoded in orval and can not be easily overridden. I also tried redefining the Blob type as an alias to ArrayBuffer via a file header or footer, but this did not work for clients where the schema components are defined in a separate file.

I'm all for a cleaner solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we allow taking the individual functions Blob type as input and when calling k6, convert it to ArrayBuffer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k6 does not support Blobs not only as a parameter to the request function, but as a runtime type in general. For example, instantiating a Blob in the script with new Blob() results in the following error:

ERRO[0000] ReferenceError: Blob is not defined

One way or another, the usage of Blobs should be replaced in the generated clients. It results in type declarations that can not be satisfied, defeating the whole point of using TypeScript.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have a blob interface in the websockets library of k6 though - https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/websockets/blob/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants