Upgrading extension from 0.37.0 to 0.42.0

Hi, team!

We have couple of custom k6 extensions implemented in golang that we use in our project. They all were written when 0.37.0 was the latest version. Recently, we decided to upgrade to 0.42.0 and discovered that there are some changes in k6 golang libs that require changes in our code.

I got couple of questions on how to do this properly:

  1. We used to pass k6 context to our functions like this:
func (*MyModule) SomeFunction(ctx context.Context, ...) {}

when compiling k6 binary for 0.42.0 and running test with it we get invalid number of parameters error - looks like context is not passed automatically to function call. has something changed in this area?

  1. We use to throw js errors in our code as the following:
common.Throw(common.GetRuntime(ctx), "some error")

In 0.42.0 GetRuntime function is deprecated in k6 common module. What is the correct way to get goja runtime in that case?

Thanks in advance for any help!

Hello hbadger! Thank you for your post.

I just wanted to throw in here to have you reference the updated guide for creating JavaScript extensions (JavaScript Extensions) which will have the newer API requirements.

Also, as a potential example, the xk6-kubernetes project was upgraded at the time with this commit.

Hope this helps!


1 Like

thank a lot! Guideline in the official docs was very useful, I was able to upgrade my extensions to 0.42.0.