Problems load testing using a Postman collection

Hi all,
My first post here.
I am trying to use a Postman collection to build a load test by following the instructions in the article here. I am able to build the k6 script, but when I execute the script it throws lots of these exceptions:

ERRO[0016] ReferenceError: escape is not defined=
    at escapeForDumbFirefox36 (file:///C:/X/Postman/libs/urijs.js:2290:10422(4))
    at core-js/shim.min.js:13:18135(6)
    at replace (core-js/shim.min.js:15:29545(29))
    at strictEncodeURIComponent (file:///C:/X/Postman/libs/urijs.js:2290:10687(9))
    at file:///C:/X/Postman/libs/urijs.js:2418:20609(27)
    at file:///C:/X/Postman/libs/urijs.js:2418:20390(5)
    at file:///C:/X/Postman/libs/urijs.js:2418:19605(42)
    at file:///C:/X/Postman/libs/urijs.js:2813:31(24)
    at file:///C:/X/Postman/libs/urijs.js:2825:22(5)
    at auth (file:///C:/X/Postman/k6-script.js:44:40(26))
    at executeRequest (file:///C:/X/Postman/libs/shim/core.js:1322:11(87))
    at executeRequest (file:///C:/X/Postman/libs/shim/core.js:1316:234(53))
    at file:///C:/X/Postman/libs/shim/core.js:670:46(35)
    at file:///C:/X/Postman/k6-script.js:35:19(16)

The results are all 0B/s, unsurprisingly :slight_smile: A Google search only turned up 1 report of this from back in 2011.

Environment:
Windows 10 Enterprise. 1909.
node v8.16.0
k6 v0.25.1
Postman file is v2.1

Anyone any ideas what I can do to fix this?

Cheers,
Geoff

Hi @glt101,

This is because k6 currently doesn’t provide an escape implementation, this actually should come from the JS VM we use - goja. Which was just added it a couple of days ago :tada: - so when we release a new version and update goja this will be fixed.
In the meantime, because postman-to-k6 doesn’t provide a shim for escape apparently, you can use something like:

//
//
var safe69chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./";

var pad02 = function(c) {
  return (Array(3).splice(c.length).join("0") + c).toUpperCase();
};

var pad04 = function(c) {
  return (Array(5).splice(c.length).join("0") + c).toUpperCase();
};


function esc(str) {

  str += '';

  for (
    var chr, chrcode, hexcode, i = -1,
      len = str.length, escaped = "";
    ++i < len;
  ) {

    chr = str.charAt(i);

    if (-1 != safe69chars.indexOf(chr)) {
      escaped += chr;
    } else {

      chrcode = chr.charCodeAt(0);
      hexcode = chrcode.toString(16);

      if (chrcode < 256) {
        escaped += ('%' + pad02(hexcode));
      } else {
        escaped += ('%u' + pad04(hexcode));
      }
    }
  }

  return escaped;
}

if (typeof escape === "undefined") {
    var escape = esc;
}

I got this from https://stackoverflow.com/a/23453108/5427244 . You need to put it on top of your script main script before your imports. The last part is specifically so if in the future when k6 has escape implementation it will be used ;).

IMO postman-to-k6 should’ve been adding this but given that k6 will get it’s escape/unescape implementation soon :tm: it is probably not worth it to report it - I will leave it up to you :wink:

Hi there,

As @mstoykov explained, there is currently no native support for escape() in the k6 tool. However, i’ve created an issue in the postman-to-k6 converter repo to add a shim in the meantime: https://github.com/loadimpact/postman-to-k6/issues/54

Until that issue has been completed and released, you’ll have to add the shim yourself to be able to run it.

Thanks,
Simme

1 Like

Hi Guys,

Thanks for the response.
Kind-a-surprised this didn’t show up before, but thanks for the help. I’ll give it a try and let you know what I find.

Cheers,
Geoff

1 Like

Hi Geoff,

I’m mostly done with extending the postman-to-k6 converter with the escape shim, but before I release it I’d like to make sure that it solves your issue. Could you please either post a sample that reproduces your issue here or email it to me on simme@k6.io?

Thanks,
Simme

FYI we updated goja version in the k6 master branch, so now this should work without a shim, if you use the master docker image (or build k6 from source yourself)

1 Like

Still awaiting a repro sample from @glt101, or anyone else experiencing this problem.