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

Commit 72f0123

Browse files
committed
Add browser registration test
1 parent 1016629 commit 72f0123

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

browser/module_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package browser
2+
3+
import (
4+
"testing"
5+
6+
"github.com/dop251/goja"
7+
"github.com/stretchr/testify/require"
8+
9+
"github.com/grafana/xk6-browser/chromium"
10+
11+
k6common "go.k6.io/k6/js/common"
12+
k6modulestest "go.k6.io/k6/js/modulestest"
13+
k6metrics "go.k6.io/k6/metrics"
14+
)
15+
16+
// TestModuleNew tests registering the module.
17+
// It doesn't test the module's remaining functionality as it is
18+
// already tested in the tests/ integration tests.
19+
func TestModuleNew(t *testing.T) {
20+
t.Parallel()
21+
22+
vu := &k6modulestest.VU{
23+
RuntimeField: goja.New(),
24+
InitEnvField: &k6common.InitEnvironment{
25+
Registry: k6metrics.NewRegistry(),
26+
},
27+
}
28+
m, ok := New().NewModuleInstance(vu).(*ModuleInstance)
29+
require.True(t, ok, "NewModuleInstance should return a ModuleInstance")
30+
require.NotNil(t, m.mod, "Module should be set")
31+
require.IsType(t, m.mod.Chromium, &chromium.BrowserType{})
32+
require.NotNil(t, m.mod.Devices, "Devices should be set")
33+
require.Equal(t, m.mod.Version, version, "Incorrect version")
34+
}

0 commit comments

Comments
 (0)