Open Shonke opened 2 years ago
Thanks for opening this issue! Indeed, the Encoding API seems like a useful one to have in k6. Though it is a Web API, not an ECMAScript one, so I am not sure if our JS runtime, goja, would be open to merging it or not :thinking: If it isn't suitable for there, we could potentially merge it into just k6, though I am not promising anything just yet.
A good first step here would be creating a well-tested JavaScript xk6 extension with the functionality. This will solve the immediate problem and greatly simplify its potential inclusion in k6.
I think it's a good idea to put it into xk6 extension
What about importing pako as a remote fslib? This could work for free (without using xk6) because neither esm nor node
Just passing by to leave an example using a much fuller polyfill
import { TextEncoder } from "https://raw.githubusercontent.com/inexorabletash/text-encoding/master/index.js"
let te = new TextEncoder()
console.log(te.encode("someString").byteLength)
console.log(te.encode("Нещо на Български").byteLength)
export default function() {} // just to not make k6 error
I have problems using this npm package https://www.npmjs.com/package/jose with k6 because it require TextDecoder and TextEncoder functions. I use it to log-in and get JWT token to use for my REST-api tests that require authentication. Ideally I would like TextDecoder and TextEncoder to be supported in k6 though...
@mstoykov Will your workaround work with 3rd party libraries that need TextDecoder and TextEncoder as well?
I have no idea @toralux as I have no idea what else jose
uses in order to know if this will be enough of a fix.
if you have file polyfill-text.js:
import { TextEncoder,TextDecoder } from "https://raw.githubusercontent.com/inexorabletash/text-encoding/master/index.js"
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
And you import it before whatever needs TextEncoder - it will be there for the dependancy
import "./polyfill-text.js"; // file from above
import jose from "./path/to/jose"; // thing needing TextEncoder
// rest of code
To what extend that will help you again depends on what else jose
or w/e needs to actually function.
@toralux 👋🏻 you might also consider my xk6-encoding extension, which provides the TextEncoder
and TextDecoder
constructs to k6. You would need to import them still, which might get in the way of solving your issue though 🙇🏻
Feature Description
I need to convert between ArrayBuffer and String. I haven't found an efficient conversion method yet I have to use encodeURI and decodeURI:
Suggested Solution (optional)
No response
Already existing or connected issues / PRs (optional)
No response