Hi,
Relatively new to k6 and to the world of performance and load testing. I was wondering if it is possible to package custom functions for my k6 script?
So I recently created a POC for testing our kafka consumer. In my POC, I have some local filesystem modules that the test script is using. I wanted to pack those local modules(without the test) into an npm package so that it can be used by other teams as well.
If it matters, I am using typescript then using webpack to bundle it including the test.
I tried searching the net but can’t seem to find the right answer or if it is even possible.
Hi @paulo.borja
You can use Webpack with some restrictions, as you can see in the docs: Modules
We have an “oldish” template that can serve as an example: GitHub - grafana/k6-template-typescript: Template to use TypeScript with k6
From your message, though:
I have some local filesystem modules
Maybe you are running into the limitation that the fs
modules will not work.
k6 is not NodeJS, nor is it a browser. Packages that rely on APIs provided by NodeJS, for instance the os
and fs
modules, will not work in k6. The same goes for browser-specific APIs like the window
object.
If you can further describe your use case and share what your common functions are doing, we might be able to point to an alternative.
Cheers!