[postman-to-k6] 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 escaping - Shim for JavaScript .escape function - Stack Overflow . 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: The converter does not include an escape shim · Issue #54 · grafana/postman-to-k6 · GitHub

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.

Hi simme,

I think the problem I’m facing might be related. I have converted a postman collection using postman-to-k6. This postman collection consists of an environment variable for changing the target URL.

I then ran the docker version of k6 in this manner:
docker run --network host -i loadimpact/k6 run --duration 30s -<myscript.js

and got the following error:
time=“2020-04-28T03:25:35Z” level=error msg=“GoError: The moduleSpecifier "file:///libs/shim/core.js" couldn’t be found on local disk. Make sure that you’ve specified the right path to the file. If you’re running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they’re accessible by k6 from inside of the container, see Modules”

running it on the non-dockerized version of k6 works

To quote part of the full k6 error message you helpfully fully posted,

If you’re running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they’re accessible by k6 from inside of the container, see https://docs.k6.io/v1.0/docs/modules#section-using-local-modules-with-docker."

Though, to be fair, the docs link has changed: Modules

thanks for the help! not sure why i didn’t see that. will we be having an updated error message inside the next docker build?

Yes, it’s already updated, docker run loadimpact/k6:master run ./nonexistent.js will give you

level=error msg="The moduleSpecifier \"file:////nonexistent.js\" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker"

Though yesterday we fixed the old docs URL to redirect to the new one anyway :smile:

1 Like