Skip to content

Commit

Permalink
Async mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed May 9, 2024
1 parent 97006d4 commit 4222f58
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions browser/mouse_mapping.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
package browser

import (
"github.com/dop251/goja"

"github.com/grafana/xk6-browser/common"
"github.com/grafana/xk6-browser/k6ext"
)

func mapMouse(_ moduleVU, m *common.Mouse) mapping {
func mapMouse(vu moduleVU, m *common.Mouse) mapping {
return mapping{
"click": m.Click,
"dblClick": m.DblClick,
"down": m.Down,
"up": m.Up,
"move": m.Move,
"click": func(x float64, y float64, opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, m.Click(x, y, opts) //nolint:wrapcheck
})
},
"dblClick": func(x float64, y float64, opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, m.DblClick(x, y, opts) //nolint:wrapcheck
})
},
"down": func(opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, m.Down(opts) //nolint:wrapcheck
})
},
"up": func(opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, m.Up(opts) //nolint:wrapcheck
})
},
"move": func(x float64, y float64, opts goja.Value) *goja.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, m.Move(x, y, opts) //nolint:wrapcheck
})
},
}
}

0 comments on commit 4222f58

Please sign in to comment.