If i have a simple script ping.js:
import http from "k6/http";
import test_case from "../../framework/test_case.js";
export let options = test_case.default_options;
export default function() {
http.get("http://test.loadimpact.com");
};
With a module test_case.js:
let default_options = {
noConnectionReuse: true,
noVUConnectionReuse: true
};
As a result of running k6 run ping.js i have received:
panic: TypeError: Cannot convert undefined or null to object--------] engine
goroutine 1 [running]:
github.com/loadimpact/k6/vendor/github.com/dop251/goja.(*Runtime).typeErrorResult(0xc420f62300, 0xc421a90601, 0xc422362430, 0x1, 0x1)
/home/user/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/runtime.go:274 +0x76
github.com/loadimpact/k6/vendor/github.com/dop251/goja.valueNull.ToObject(0xc420f62300, 0x20f7e20)
/home/user/go/src/github.com/loadimpact/k6/vendor/github.com/dop251/goja/value.go:337 +0x6c
github.com/loadimpact/k6/js.(*Bundle).Instantiate(0xc421bdfe00, 0xc42366d9e8, 0x0, 0x0)
/home/user/go/src/github.com/loadimpact/k6/js/bundle.go:226 +0x263
github.com/loadimpact/k6/js.(*Runner).newVU(0xc420196360, 0xc422280f00, 0x1868820, 0x105ec01, 0xc421476500)
/home/user/go/src/github.com/loadimpact/k6/js/runner.go:115 +0x46
github.com/loadimpact/k6/js.(*Runner).NewVU(0xc420196360, 0xc422280f00, 0xc420524cb0, 0x1, 0xc42366d9e8, 0xc4237ec1e0)
/home/user/go/src/github.com/loadimpact/k6/js/runner.go:106 +0x35
github.com/loadimpact/k6/core/local.(*Executor).SetVUsMax(0xc420524c60, 0x1, 0x0, 0x0)
/home/user/go/src/github.com/loadimpact/k6/core/local/local.go:528 +0x34e
github.com/loadimpact/k6/core.NewEngine(0x1a91460, 0xc420524c60, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, ...)
/home/user/go/src/github.com/loadimpact/k6/core/engine.go:85 +0x167
github.com/loadimpact/k6/cmd.glob..func11(0x20ced40, 0xc420754490, 0x1, 0x1, 0x0, 0x0)
/home/user/go/src/github.com/loadimpact/k6/cmd/run.go:179 +0xd3d
github.com/loadimpact/k6/vendor/github.com/spf13/cobra.(*Command).execute(0x20ced40, 0xc420754460, 0x1, 0x1, 0x20ced40, 0xc420754460)
/home/user/go/src/github.com/loadimpact/k6/vendor/github.com/spf13/cobra/command.go:698 +0x46d
github.com/loadimpact/k6/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0x20ceb20, 0x52, 0xc42068c140, 0xc42077e000)
/home/user/go/src/github.com/loadimpact/k6/vendor/github.com/spf13/cobra/command.go:783 +0x2e4
github.com/loadimpact/k6/vendor/github.com/spf13/cobra.(*Command).Execute(0x20ceb20, 0xc420791f78, 0x1003abc)
/home/user/go/src/github.com/loadimpact/k6/vendor/github.com/spf13/cobra/command.go:736 +0x2b
github.com/loadimpact/k6/cmd.Execute()
/home/user/go/src/github.com/loadimpact/k6/cmd/root.go:87 +0x31
main.main()
/home/user/go/src/github.com/loadimpact/k6/main.go:28 +0x20
In the version 0.22.0 it was working fine.
Right now it blocks all my current tests, so for me its very important.
If i change the script into:
import http from "k6/http";
export let options = {
noConnectionReuse: true,
noVUConnectionReuse: true
};;
export default function() {
http.get("http://test.loadimpact.com");
};
It works fine (great! :))
Thank you in advance.
Michal
Thanks for reporting this, it's likely due to my attempts to improve the fixes of https://github.com/loadimpact/k6/issues/613, I'll investigate and fix it as soon as possible.
Hmm I think that this is a combination of a bug in k6 that was revealed by a small bug with the way you use ES6 modules in your code. If I execute the following minimal example code in k6 version 0.22.0 and before:
import test_case from "./test_case.js";
export let options = test_case.default_options;
export default function () {
console.log(JSON.stringify(options));
console.log(JSON.stringify(test_case.default_options));
};
where test_case.js has the same contents as in your example, I'll get something like this:
INFO[0000] undefined
INFO[0000] undefined
and of course, with k6 0.22.1, the example panics with a TypeError like you showed. But the key fact here is that you haven't actually exported the default_options in test_case.js, so they're not visible in the main script file. If instead the contents of test_case.js were something like this:
export default {
default_options: {
noConnectionReuse: true,
noVUConnectionReuse: true
}
};
then it will work like you expect it to work in all k6 versions, including 0.22.1.
Still, in your original example k6 panics when it tries to set option keys in that undefined value, which shouldn't happen and is a bug that I'll fix with a pull request shortly.
Thank you for the explanation.
Actually my bad, at the top of the test_case script i had an old fashioned module.exports.
Thank you for that. All i had to do, is replace module.exports with export default.