k6 icon indicating copy to clipboard operation
k6 copied to clipboard

Module exports might be getting wrapped by goja a lot

Open mstoykov opened this issue 1 year ago • 0 comments

What?

Currently most go modules that export something will just have is a none goja.Value in the modules#Exports. But goja practically only works with goja.Value. So in practically any place where this will be "imported" - it will also be wrapped in one.

This does mean that something simple such as

export default function() { } // to skip error

import k6 from "k6";

console.log(k6.check == k6.check);

will log false .

Some modules such as k6/http has practically fixed this by having a real goja Object instead of expecting that if it had map[string]func()... it will do the right thing.

I hit this while making test for https://github.com/grafana/k6/pull/3706 https://github.com/grafana/k6/blob/191c9610fd153204344690752a83a0467d7f224a/js/modules/k6/timers/timers.go#L67-L70

mstoykov avatar Apr 23 '24 15:04 mstoykov