Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k6/execution:Don't panic on accessing test.options #3708

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion js/modules/k6/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ func (mi *ModuleInstance) newTestInfo() (*goja.Object, error) {
}
},
"options": func() interface{} {
vuState := mi.vu.State()
if vuState == nil {
common.Throw(rt, fmt.Errorf("getting test options in the init context is not supported"))
mstoykov marked this conversation as resolved.
Show resolved Hide resolved
}
if optionsObject == nil {
opts, err := optionsAsObject(rt, mi.vu.State().Options)
opts, err := optionsAsObject(rt, vuState.Options)
if err != nil {
common.Throw(rt, err)
}
Expand Down
17 changes: 17 additions & 0 deletions js/modules/k6/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,23 @@ func TestScenarioNoAvailableInInitContext(t *testing.T) {
}
}

func TestOptionsNoAvailableInInitContext(t *testing.T) {
t.Parallel()

rt := goja.New()
m, ok := New().NewModuleInstance(
&modulestest.VU{
RuntimeField: rt,
CtxField: context.Background(),
},
).(*ModuleInstance)
require.True(t, ok)
require.NoError(t, rt.Set("exec", m.Exports().Default))

_, err := rt.RunString("exec.test.options")
require.ErrorContains(t, err, "getting test options in the init context is not supported")
}

func TestVUDefaultDetails(t *testing.T) {
t.Parallel()

Expand Down