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

Commit 44a2760

Browse files
committed
Refactor Parse to accept a logger
1 parent f39e48a commit 44a2760

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

chromium/browser_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (b *BrowserType) Launch(opts goja.Value) api.Browser {
133133
}
134134

135135
launchOpts := common.NewLaunchOptions()
136-
if err := launchOpts.Parse(ctx, opts); err != nil {
136+
if err := launchOpts.Parse(ctx, opts, b.logger); err != nil {
137137
k6ext.Panic(ctx, "parsing launch options: %w", err)
138138
}
139139
ctx = common.WithLaunchOptions(ctx, launchOpts)

common/browser_options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/dop251/goja"
99

1010
"github.com/grafana/xk6-browser/k6ext"
11+
"github.com/grafana/xk6-browser/log"
1112
)
1213

1314
// ProxyOptions allows configuring a proxy server.
@@ -41,17 +42,16 @@ type LaunchPersistentContextOptions struct {
4142

4243
// NewLaunchOptions returns a new LaunchOptions.
4344
func NewLaunchOptions() *LaunchOptions {
44-
launchOpts := LaunchOptions{
45+
return &LaunchOptions{
4546
Env: make(map[string]string),
4647
Headless: true,
4748
LogCategoryFilter: ".*",
4849
Timeout: DefaultTimeout,
4950
}
50-
return &launchOpts
5151
}
5252

5353
// Parse parses launch options from a JS object.
54-
func (l *LaunchOptions) Parse(ctx context.Context, opts goja.Value) error { //nolint:cyclop
54+
func (l *LaunchOptions) Parse(ctx context.Context, opts goja.Value, logger *log.Logger) error { //nolint:cyclop
5555
if !gojaValueExists(opts) {
5656
return errors.New("LaunchOptions does not exist in the runtime")
5757
}

common/browser_options_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
"github.com/grafana/xk6-browser/k6ext/k6test"
11+
"github.com/grafana/xk6-browser/log"
1112
)
1213

1314
func TestBrowserLaunchOptionsParse(t *testing.T) {
@@ -213,7 +214,7 @@ func TestBrowserLaunchOptionsParse(t *testing.T) {
213214
vu = k6test.NewVU(t)
214215
lo = NewLaunchOptions()
215216
)
216-
err := lo.Parse(vu.Context(), vu.ToGojaValue(tt.opts))
217+
err := lo.Parse(vu.Context(), vu.ToGojaValue(tt.opts), log.NewNullLogger())
217218
if tt.err != "" {
218219
require.ErrorContains(t, err, tt.err)
219220
} else {

common/browser_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func TestBrowserNewPageInContext(t *testing.T) {
2323
}
2424
newTestCase := func(id cdp.BrowserContextID) *testCase {
2525
ctx, cancel := context.WithCancel(context.Background())
26-
b := newBrowser(ctx, cancel, nil, NewLaunchOptions(), log.NewNullLogger())
26+
logger := log.NewNullLogger()
27+
b := newBrowser(ctx, cancel, nil, NewLaunchOptions(), logger)
2728
// set a new browser context in the browser with `id`, so that newPageInContext can find it.
2829
b.contexts[id] = NewBrowserContext(ctx, b, id, nil, nil)
2930
return &testCase{

0 commit comments

Comments
 (0)