Upgrade to v0.32 TypeError: Object has no member 'reduce'

Upgraded to v0.32.0 from 0.31.1 and now tests fail to run, breaking at the reduce.

Specifically in this helper function:

import { randomBytes } from 'k6/crypto';

function createRequestId() {
  return randomBytes(8).reduce(
    (output, elem) => output + `0${elem.toString(16)}`.slice(-2),'');
}

with the error
TypeError: Object has no member 'reduce'

Any idea why? I downgraded back to v0.31.1 to avoid it.

Sorry for the inconvenience, we had to make that breaking change in v0.32.0 to get uniform and sane handling of binary data everywhere. As we mention in the release notes, you can wrap the newly returned ArrayBuffer in a JS typed array to get almost exactly the same behavior as before, like this:

import { randomBytes } from 'k6/crypto';

function createRequestId() {
  return (new Uint8Array(randomBytes(8))).reduce(
    (output, elem) => output + `0${elem.toString(16)}`.slice(-2), '');
}
1 Like