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

Commit 4e157b0

Browse files
committed
Add goja mappings to the module
With this, the browser module exposes api types to goja mappings to users.
1 parent cf054df commit 4e157b0

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

browser/mapping.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
k6modules "go.k6.io/k6/js/modules"
1313
)
1414

15-
var _ = mapBrowserToGoja(nil)
16-
1715
// mapping is a type of mapping between our API (api/) and the JS
1816
// module. It acts like a bridge and allows adding wildcard methods
1917
// and customization over our API.

browser/module.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"errors"
66
"os"
77

8-
"github.com/grafana/xk6-browser/api"
9-
"github.com/grafana/xk6-browser/chromium"
8+
"github.com/dop251/goja"
9+
1010
"github.com/grafana/xk6-browser/common"
1111

1212
k6common "go.k6.io/k6/js/common"
@@ -22,7 +22,7 @@ type (
2222

2323
// JSModule exposes the properties available to the JS script.
2424
JSModule struct {
25-
Chromium api.BrowserType
25+
Chromium *goja.Object
2626
Devices map[string]common.Device
2727
Version string
2828
}
@@ -57,7 +57,7 @@ func (*RootModule) NewModuleInstance(vu k6modules.VU) k6modules.Instance {
5757

5858
return &ModuleInstance{
5959
mod: &JSModule{
60-
Chromium: chromium.NewBrowserType(vu),
60+
Chromium: mapBrowserToGoja(vu),
6161
Devices: common.GetDevices(),
6262
Version: version,
6363
},

browser/module_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
99

10-
"github.com/grafana/xk6-browser/chromium"
11-
1210
k6common "go.k6.io/k6/js/common"
1311
k6modulestest "go.k6.io/k6/js/modulestest"
1412
k6metrics "go.k6.io/k6/metrics"
@@ -29,7 +27,7 @@ func TestModuleNew(t *testing.T) {
2927
m, ok := New().NewModuleInstance(vu).(*ModuleInstance)
3028
require.True(t, ok, "NewModuleInstance should return a ModuleInstance")
3129
require.NotNil(t, m.mod, "Module should be set")
32-
require.IsType(t, m.mod.Chromium, &chromium.BrowserType{})
30+
require.NotNil(t, m.mod.Chromium, "Chromium should be set")
3331
require.NotNil(t, m.mod.Devices, "Devices should be set")
3432
require.Equal(t, m.mod.Version, version, "Incorrect version")
3533
}

0 commit comments

Comments
 (0)