|
| 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