@@ -12,8 +12,6 @@ import (
12
12
"github.com/grafana/xk6-browser/k6ext"
13
13
14
14
k6modules "go.k6.io/k6/js/modules"
15
-
16
- "github.com/dop251/goja"
17
15
)
18
16
19
17
const version = "v0.4.0"
@@ -23,12 +21,11 @@ type (
23
21
// instances for each VU.
24
22
RootModule struct {}
25
23
26
- // JSModule is the entrypoint into the browser JS module .
24
+ // JSModule exposes the properties available to the JS script .
27
25
JSModule struct {
28
- vu k6modules.VU
29
- k6Metrics * k6ext.CustomMetrics
30
- Devices map [string ]common.Device
31
- Version string
26
+ Chromium api.BrowserType
27
+ Devices map [string ]common.Device
28
+ Version string
32
29
}
33
30
34
31
// ModuleInstance represents an instance of the JS module.
@@ -61,34 +58,22 @@ func New() *RootModule {
61
58
// a new instance for each VU.
62
59
func (* RootModule ) NewModuleInstance (vu k6modules.VU ) k6modules.Instance {
63
60
k6m := k6ext .RegisterCustomMetrics (vu .InitEnv ().Registry )
61
+ ctx := k6ext .WithVU (vu .Context (), vu )
62
+ ctx = k6ext .WithCustomMetrics (ctx , k6m )
63
+
64
64
return & ModuleInstance {
65
65
mod : & JSModule {
66
- vu : vu ,
67
- k6Metrics : k6m ,
68
- Devices : common .GetDevices (),
69
- Version : version ,
66
+ Chromium : chromium .NewBrowserType (ctx ),
67
+ Devices : common .GetDevices (),
68
+ Version : version ,
70
69
},
71
70
}
72
71
}
73
72
74
73
// Exports returns the exports of the JS module so that it can be used in test
75
74
// scripts.
76
75
func (mi * ModuleInstance ) Exports () k6modules.Exports {
77
- return k6modules.Exports {
78
- Named : map [string ]interface {}{
79
- "chromium" : mi .mod ,
80
- "devices" : mi .mod .Devices ,
81
- },
82
- }
83
- }
84
-
85
- // Launch Chromium with given options.
86
- func (m * JSModule ) Launch (opts goja.Value ) api.Browser {
87
- ctx := k6ext .WithVU (m .vu .Context (), m .vu )
88
- ctx = k6ext .WithCustomMetrics (ctx , m .k6Metrics )
89
-
90
- bt := chromium .NewBrowserType (ctx )
91
- return bt .Launch (opts )
76
+ return k6modules.Exports {Default : mi .mod }
92
77
}
93
78
94
79
func init () {
0 commit comments