k6 icon indicating copy to clipboard operation
k6 copied to clipboard

`console.log`: Improve ArrayBuffer/TypedArray output formatting (Option 2)

Open pkalsi97 opened this issue 2 weeks ago • 1 comments

Feature Description

Improve console.log output formatting for ArrayBuffer and TypedArray by modifying the traverseValue function to avoid json.Marshal entirely.

Suggested Solution (optional)

Following the discussion in #5469, two options were explored to achieve Deno-style output for ArrayBuffer and TypedArray:

  • Option 1 (implemented in #5480): Uses json.Encoder with SetEscapeHTML(false). This prevents <>\u003c\u003e escaping but retains extra quotes around formatted strings for nested objects.
{ "b": "ArrayBuffer { [Uint8Contents]: <00 00 00 00 00 00 00 00>, byteLength: 8 }", "v": "Int32Array(2) [ 4, 2 ]" }
  • Option 2 (this issue): Modifies traverseValue to avoid json.Marshal entirely, achieving:
    • No HTML escaping (<> stays as <>)
    • No extra quotes around formatted strings
    • Output style: { key: value } for objects and [ elem, elem ] for arrays
    • Fully matches Deno-style output
{ b: ArrayBuffer { [Uint8Contents]: <00 00 00 00 00 00 00 00>, byteLength: 8 }, v: Int32Array(2) [ 4, 2 ] }

Already existing or connected issues / PRs (optional)

Original issue: #5469 Option 1 implementation: #5480

pkalsi97 avatar Dec 12 '25 05:12 pkalsi97

@inancgumus I have created this issue for Implementation of Option 2, followed it with a PR implementing the same. Thanks.

pkalsi97 avatar Dec 12 '25 06:12 pkalsi97

Closing as per @inancgumus - resolution going towards Option 2 in the main issue

pkalsi97 avatar Dec 12 '25 17:12 pkalsi97