Skip to content

Commit

Permalink
Add runJSInEventLoop
Browse files Browse the repository at this point in the history
This is a custom function for TestWaitForFunction to allow it to run
the async API in an event loop.
  • Loading branch information
ankur22 committed Jan 24, 2024
1 parent 80598a1 commit 97420ec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,24 @@ func startIteration(t *testing.T) (*k6test.VU, *goja.Runtime, *[]string, func())
return vu, rt, &log, func() { t.Helper(); vu.EndIteration(t) }
}

func runJSInEventLoop(t *testing.T, vu *k6test.VU, js string) error {
t.Helper()

rt := vu.Runtime()
_, err := rt.RunString(js)
require.NoError(t, err)

test, ok := goja.AssertFunction(rt.Get("test"))

This comment has been minimized.

Copy link
@ankur22

ankur22 Jan 24, 2024

Author Collaborator

Yep, i was wondering that too. Sure, i'll try to make that change.

require.True(t, ok)

err = vu.Loop.Start(func() error {
_, err := test(goja.Undefined())
return err
})

return err
}

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

Expand Down

0 comments on commit 97420ec

Please sign in to comment.