Skip to content

Commit

Permalink
Make Tap async
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Apr 18, 2024
1 parent fcbd86a commit 7e8cb89
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
32 changes: 20 additions & 12 deletions browser/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping {
"press": lo.Press,
"type": lo.Type,
"hover": lo.Hover,
"tap": func(opts goja.Value) error {
"tap": func(opts goja.Value) (*goja.Promise, error) {
copts := common.NewFrameTapOptions(lo.DefaultTimeout())
if err := copts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing locator tap options: %w", err)
return nil, fmt.Errorf("parsing locator tap options: %w", err)
}
return lo.Tap(copts) //nolint:wrapcheck
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, lo.Tap(copts) //nolint:wrapcheck
}), nil
},
"dispatchEvent": func(typ string, eventInit, opts goja.Value) error {
popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout())
Expand Down Expand Up @@ -304,12 +306,14 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping {
"selectOption": eh.SelectOption,
"selectText": eh.SelectText,
"setInputFiles": eh.SetInputFiles,
"tap": func(opts goja.Value) error {
"tap": func(opts goja.Value) (*goja.Promise, error) {
popts := common.NewElementHandleTapOptions(eh.Timeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing element tap options: %w", err)
return nil, fmt.Errorf("parsing element tap options: %w", err)
}
return eh.Tap(popts) //nolint:wrapcheck
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, eh.Tap(popts) //nolint:wrapcheck
}), nil
},
"textContent": eh.TextContent,
"type": eh.Type,
Expand Down Expand Up @@ -462,12 +466,14 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping {
"selectOption": f.SelectOption,
"setContent": f.SetContent,
"setInputFiles": f.SetInputFiles,
"tap": func(selector string, opts goja.Value) error {
"tap": func(selector string, opts goja.Value) (*goja.Promise, error) {
popts := common.NewFrameTapOptions(f.Timeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing frame tap options: %w", err)
return nil, fmt.Errorf("parsing frame tap options: %w", err)
}
return f.Tap(selector, popts) //nolint:wrapcheck
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, f.Tap(selector, popts) //nolint:wrapcheck
}), nil
},
"textContent": f.TextContent,
"title": f.Title,
Expand Down Expand Up @@ -721,12 +727,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
"setExtraHTTPHeaders": p.SetExtraHTTPHeaders,
"setInputFiles": p.SetInputFiles,
"setViewportSize": p.SetViewportSize,
"tap": func(selector string, opts goja.Value) error {
"tap": func(selector string, opts goja.Value) (*goja.Promise, error) {
popts := common.NewFrameTapOptions(p.Timeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return fmt.Errorf("parsing page tap options: %w", err)
return nil, fmt.Errorf("parsing page tap options: %w", err)
}
return p.Tap(selector, popts) //nolint:wrapcheck
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, p.Tap(selector, popts) //nolint:wrapcheck
}), nil
},
"textContent": p.TextContent,
"throttleCPU": p.ThrottleCPU,
Expand Down
8 changes: 4 additions & 4 deletions browser/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ type pageAPI interface {
SetExtraHTTPHeaders(headers map[string]string)
SetInputFiles(selector string, files goja.Value, opts goja.Value)
SetViewportSize(viewportSize goja.Value)
Tap(selector string, opts goja.Value) error
Tap(selector string, opts goja.Value) (*goja.Promise, error)
TextContent(selector string, opts goja.Value) string
ThrottleCPU(common.CPUProfile) error
ThrottleNetwork(common.NetworkProfile) error
Expand Down Expand Up @@ -413,7 +413,7 @@ type frameAPI interface {
SelectOption(selector string, values goja.Value, opts goja.Value) []string
SetContent(html string, opts goja.Value)
SetInputFiles(selector string, files goja.Value, opts goja.Value)
Tap(selector string, opts goja.Value) error
Tap(selector string, opts goja.Value) (*goja.Promise, error)
TextContent(selector string, opts goja.Value) string
Title() string
Type(selector string, text string, opts goja.Value)
Expand Down Expand Up @@ -458,7 +458,7 @@ type elementHandleAPI interface {
SelectOption(values goja.Value, opts goja.Value) []string
SelectText(opts goja.Value)
SetInputFiles(files goja.Value, opts goja.Value)
Tap(opts goja.Value) error
Tap(opts goja.Value) (*goja.Promise, error)
TextContent() string
Type(text string, opts goja.Value)
Uncheck(opts goja.Value)
Expand Down Expand Up @@ -533,7 +533,7 @@ type locatorAPI interface {
Press(key string, opts goja.Value)
Type(text string, opts goja.Value)
Hover(opts goja.Value)
Tap(opts goja.Value) error
Tap(opts goja.Value) (*goja.Promise, error)
DispatchEvent(typ string, eventInit, opts goja.Value)
WaitFor(opts goja.Value)
}
Expand Down

0 comments on commit 7e8cb89

Please sign in to comment.