A newer version of faker

I have been using Faker and it works well.

import http from 'k6/http';
import { check } from 'k6';
import { faker } from 'https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js';

However, v3.1.0 is 7 years old-ish now and therefore before the events of this year. It has been forked and this now seems to be the official version of it.

I can’t, however, seem to get the newer version to play at all with k6. This seems to be the most relevant method.

Replacing the third line above, with this, doesn’t work, however:

import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';

I end up with the below error:

I understand I can use K6_DEBUG_SOURCEMAP_FILESIZE_LIMIT=524288 to increase the limit – but have no idea where I add this? Or will upping this limit even resolve the issue?

Faker is incredibly useful, and it would be awesome to make use of a newer version. Just unsure how I go about it.

Thanks!

Hi @Lewys,

Thanks for sharing.

The warning could be removed if you increase the K6_DEBUG_SOURCEMAP_FILESIZE_LIMIT environment variable. As documented here, you can pass the variable to k6. E.g. K6_DEBUG_SOURCEMAP_FILESIZE_LIMIT=800000 k6 run script.js.

However this is a just a warning, and as you well point out, not the cause of the error that appears next. In this scenario you’ll most probably won’t need sourcemap enabled, so you can leave the warning.

As per the root cause of the error, @mstoykov pointed me to a known issue: JavaScript spread operator throws error with params object · Issue #824 · grafana/k6 · GitHub with the JS spread operator. You can follow the conversation there. You won’t be able to use faker v7 until that is addressed.

That said, we would recommend to roll your own fake function if you are using faker for only a few things. Our testing with the “old” faker shows that for 1000 VUs it’s using 8Gb memory. It’s an interesting point to make, and we went ahead and opened Faker with SharedArray to use less memory · Issue #84 · grafana/jslib.k6.io · GitHub to consider building a SharedArray that loads faker data with lower memory footprint.

Cheers!