Skip to content

Commit

Permalink
k6/execution:Don't panic on accessing test.options
Browse files Browse the repository at this point in the history
  • Loading branch information
mstoykov committed Apr 24, 2024
1 parent b866c10 commit df96679
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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"))
}
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

0 comments on commit df96679

Please sign in to comment.