k6
k6 copied to clipboard
Add `console.log` support for `ArrayBuffer` and `TypedArray` (Option 2)
What?
This PR adds support for console.log for ArrayBuffer and TypedArray by implementing Option 2, replaces JSON marshaling with direct string formatting to achieve Deno-style output for console.log:
- Objects display as
{ key: value }instead of{"key":"value"} - Arrays display as
[ elem, elem ]instead of["elem","elem"] - TypedArrays display as
Int32Array(2) [ 4, 2 ] - ArrayBuffer displays as
ArrayBuffer { [Uint8Contents]: <...>, byteLength: N } - Nested TypedArray/ArrayBuffer no longer have extra quotes
Result
--- Direct Cases ---
Int32Array(2) [ 4, 2 ]
ArrayBuffer { [Uint8Contents]: <04 00 00 00 02 00 00 00>, byteLength: 8 }
--- Nested Cases ---
{ v: Int32Array(2) [ 4, 2 ] }
{ b: ArrayBuffer { [Uint8Contents]: <...>, byteLength: 8 } }
--- Regular Objects ---
{ foo: "bar" }
[ 1, 2, 3 ]
--- Complex Nested ---
{ name: "test", buffer: ArrayBuffer {...}, view: Int32Array(2) [...], nested: {...} }
Changes
- Remove
json.Marshaldependency fromtraverseValue, it now returnsstringdirectly. - Update all test expectations for the new output format and add new test cases for
TypedArraytypes andArrayBuffer
Why?
See #5469 for details.
Checklist
- [x] I have performed a self-review of my code.
- [x] I have commented on my code, particularly in hard-to-understand areas.
- [x] I have added tests for my changes.
- [x] I have run linter and tests locally (
make check) and all pass.
Checklist: Documentation (only for k6 maintainers and if relevant)
- [ ] I have added the correct milestone and labels to the PR.
- [ ] I have updated the release notes: link
- [ ] I have updated or added an issue to the k6-documentation: grafana/k6-docs#NUMBER if applicable
- [ ] I have updated or added an issue to the TypeScript definitions: grafana/k6-DefinitelyTyped#NUMBER if applicable
Related PR(s)/Issue(s)
- Original Issue: https://github.com/grafana/k6/issues/5469
- New Issue (Option 2): https://github.com/grafana/k6/issues/5495
- PR Implementing Option 1: #5480
Adding myself and @inancgumus to this review, as we've been collaborating with @pkalsi97 to frame this topic 🙇♂️
@inancgumus nice idea, I have implemented it. Thanks!