Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 982e39c

Browse files
committed
Make Tap async
1 parent 64c825d commit 982e39c

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

browser/mapping.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ func mapLocator(vu moduleVU, lo *common.Locator) mapping {
8282
"press": lo.Press,
8383
"type": lo.Type,
8484
"hover": lo.Hover,
85-
"tap": func(opts goja.Value) error {
85+
"tap": func(opts goja.Value) (*goja.Promise, error) {
8686
copts := common.NewFrameTapOptions(lo.DefaultTimeout())
8787
if err := copts.Parse(vu.Context(), opts); err != nil {
88-
return fmt.Errorf("parsing locator tap options: %w", err)
88+
return nil, fmt.Errorf("parsing locator tap options: %w", err)
8989
}
90-
return lo.Tap(copts) //nolint:wrapcheck
90+
return k6ext.Promise(vu.Context(), func() (any, error) {
91+
return nil, lo.Tap(copts) //nolint:wrapcheck
92+
}), nil
9193
},
9294
"dispatchEvent": func(typ string, eventInit, opts goja.Value) error {
9395
popts := common.NewFrameDispatchEventOptions(lo.DefaultTimeout())
@@ -286,12 +288,14 @@ func mapElementHandle(vu moduleVU, eh *common.ElementHandle) mapping {
286288
"selectOption": eh.SelectOption,
287289
"selectText": eh.SelectText,
288290
"setInputFiles": eh.SetInputFiles,
289-
"tap": func(opts goja.Value) error {
291+
"tap": func(opts goja.Value) (*goja.Promise, error) {
290292
popts := common.NewElementHandleTapOptions(eh.Timeout())
291293
if err := popts.Parse(vu.Context(), opts); err != nil {
292-
return fmt.Errorf("parsing element tap options: %w", err)
294+
return nil, fmt.Errorf("parsing element tap options: %w", err)
293295
}
294-
return eh.Tap(popts) //nolint:wrapcheck
296+
return k6ext.Promise(vu.Context(), func() (any, error) {
297+
return nil, eh.Tap(popts) //nolint:wrapcheck
298+
}), nil
295299
},
296300
"textContent": eh.TextContent,
297301
"type": eh.Type,
@@ -442,12 +446,14 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping {
442446
"selectOption": f.SelectOption,
443447
"setContent": f.SetContent,
444448
"setInputFiles": f.SetInputFiles,
445-
"tap": func(selector string, opts goja.Value) error {
449+
"tap": func(selector string, opts goja.Value) (*goja.Promise, error) {
446450
popts := common.NewFrameTapOptions(f.Timeout())
447451
if err := popts.Parse(vu.Context(), opts); err != nil {
448-
return fmt.Errorf("parsing frame tap options: %w", err)
452+
return nil, fmt.Errorf("parsing frame tap options: %w", err)
449453
}
450-
return f.Tap(selector, popts) //nolint:wrapcheck
454+
return k6ext.Promise(vu.Context(), func() (any, error) {
455+
return nil, f.Tap(selector, popts) //nolint:wrapcheck
456+
}), nil
451457
},
452458
"textContent": f.TextContent,
453459
"title": f.Title,
@@ -690,12 +696,14 @@ func mapPage(vu moduleVU, p *common.Page) mapping {
690696
"setExtraHTTPHeaders": p.SetExtraHTTPHeaders,
691697
"setInputFiles": p.SetInputFiles,
692698
"setViewportSize": p.SetViewportSize,
693-
"tap": func(selector string, opts goja.Value) error {
699+
"tap": func(selector string, opts goja.Value) (*goja.Promise, error) {
694700
popts := common.NewFrameTapOptions(p.Timeout())
695701
if err := popts.Parse(vu.Context(), opts); err != nil {
696-
return fmt.Errorf("parsing page tap options: %w", err)
702+
return nil, fmt.Errorf("parsing page tap options: %w", err)
697703
}
698-
return p.Tap(selector, popts) //nolint:wrapcheck
704+
return k6ext.Promise(vu.Context(), func() (any, error) {
705+
return nil, p.Tap(selector, popts) //nolint:wrapcheck
706+
}), nil
699707
},
700708
"textContent": p.TextContent,
701709
"throttleCPU": p.ThrottleCPU,

browser/mapping_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ type pageAPI interface {
322322
SetExtraHTTPHeaders(headers map[string]string)
323323
SetInputFiles(selector string, files goja.Value, opts goja.Value)
324324
SetViewportSize(viewportSize goja.Value)
325-
Tap(selector string, opts goja.Value) error
325+
Tap(selector string, opts goja.Value) (*goja.Promise, error)
326326
TextContent(selector string, opts goja.Value) string
327327
ThrottleCPU(common.CPUProfile) error
328328
ThrottleNetwork(common.NetworkProfile) error
@@ -387,7 +387,7 @@ type frameAPI interface {
387387
SelectOption(selector string, values goja.Value, opts goja.Value) []string
388388
SetContent(html string, opts goja.Value)
389389
SetInputFiles(selector string, files goja.Value, opts goja.Value)
390-
Tap(selector string, opts goja.Value) error
390+
Tap(selector string, opts goja.Value) (*goja.Promise, error)
391391
TextContent(selector string, opts goja.Value) string
392392
Title() string
393393
Type(selector string, text string, opts goja.Value)
@@ -432,7 +432,7 @@ type elementHandleAPI interface {
432432
SelectOption(values goja.Value, opts goja.Value) []string
433433
SelectText(opts goja.Value)
434434
SetInputFiles(files goja.Value, opts goja.Value)
435-
Tap(opts goja.Value) error
435+
Tap(opts goja.Value) (*goja.Promise, error)
436436
TextContent() string
437437
Type(text string, opts goja.Value)
438438
Uncheck(opts goja.Value)
@@ -502,7 +502,7 @@ type locatorAPI interface {
502502
Press(key string, opts goja.Value)
503503
Type(text string, opts goja.Value)
504504
Hover(opts goja.Value)
505-
Tap(opts goja.Value) error
505+
Tap(opts goja.Value) (*goja.Promise, error)
506506
DispatchEvent(typ string, eventInit, opts goja.Value)
507507
WaitFor(opts goja.Value)
508508
}

0 commit comments

Comments
 (0)