Skip to content

Commit

Permalink
Refactor parseBrowserContextOptions to Sobek RT
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 6, 2024
1 parent a3a136b commit 8a891d6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions browser/browser_context_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestBrowserContextOptionsPermissions(t *testing.T) {
vu := k6test.NewVU(t)

opts, err := parseBrowserContextOptions(vu.Context(), vu.ToSobekValue((struct {
opts, err := parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
Permissions []any `js:"permissions"`
}{
Permissions: []any{"camera", "microphone"},
Expand All @@ -25,7 +25,7 @@ func TestBrowserContextOptionsPermissions(t *testing.T) {
func TestBrowserContextSetGeolocation(t *testing.T) {
vu := k6test.NewVU(t)

opts, err := parseBrowserContextOptions(vu.Context(), vu.ToSobekValue((struct {
opts, err := parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
GeoLocation *common.Geolocation `js:"geolocation"`
}{
GeoLocation: &common.Geolocation{
Expand Down
9 changes: 4 additions & 5 deletions browser/browser_mapping.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package browser

import (
"context"
"fmt"

"github.com/grafana/sobek"
Expand Down Expand Up @@ -37,7 +36,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop,gocognit
return b.IsConnected(), nil
},
"newContext": func(opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseBrowserContextOptions(vu.Context(), opts)
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newContext options: %w", err)
}
Expand Down Expand Up @@ -72,7 +71,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop,gocognit
return b.Version(), nil
},
"newPage": func(opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseBrowserContextOptions(vu.Context(), opts)
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newPage options: %w", err)
}
Expand Down Expand Up @@ -110,12 +109,12 @@ func initBrowserContext(bctx *common.BrowserContext, testRunID string) error {
}

// parseBrowserContextOptions parses the [common.BrowserContext] options from a Sobek value.
func parseBrowserContextOptions(ctx context.Context, opts sobek.Value) (*common.BrowserContextOptions, error) {
func parseBrowserContextOptions(rt *sobek.Runtime, opts sobek.Value) (*common.BrowserContextOptions, error) {
if !sobekValueExists(opts) {
return nil, nil //nolint:nilnil
}
b := common.NewBrowserContextOptions()
if err := k6ext.Runtime(ctx).ExportTo(opts, &b); err != nil {
if err := rt.ExportTo(opts, &b); err != nil {
return nil, fmt.Errorf("parsing browser context options: %w", err)
}
return b, nil
Expand Down
4 changes: 2 additions & 2 deletions browser/sync_browser_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
return b.IsConnected(), nil
},
"newContext": func(opts sobek.Value) (*sobek.Object, error) {
popts, err := parseBrowserContextOptions(vu.Context(), opts)
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newContext options: %w", err)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func syncMapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
return b.Version(), nil
},
"newPage": func(opts sobek.Value) (mapping, error) {
popts, err := parseBrowserContextOptions(vu.Context(), opts)
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newPage options: %w", err)
}
Expand Down
Binary file removed example-chromium.png
Binary file not shown.

0 comments on commit 8a891d6

Please sign in to comment.