Documentation ¶
Overview ¶
Package k6ext acts as an encapsulation layer between the k6 core and xk6-browser.
Index ¶
- func Abort(ctx context.Context, format string, a ...any)
- func GetScenarioName(ctx context.Context) string
- func GetScenarioOpts(ctx context.Context, vu k6modules.VU) map[string]any
- func GetVU(ctx context.Context) k6modules.VU
- func Panic(ctx context.Context, format string, a ...any)
- func Promise(ctx context.Context, fn PromisifiedFunc) *sobek.Promise
- func Runtime(ctx context.Context) *sobek.Runtime
- func WithCustomMetrics(ctx context.Context, k6m *CustomMetrics) context.Context
- func WithVU(ctx context.Context, vu k6modules.VU) context.Context
- type CustomMetrics
- type PromisifiedFunc
- type UserFriendlyError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abort ¶ added in v0.9.0
Abort will shutdown the whole test run. This should only be used from the sobek mapping layer. It is only to be used when an error will occur in all iterations, so it's permanent.
func GetScenarioName ¶ added in v1.0.0
GetScenarioName returns the scenario name associated with the given context.
func GetScenarioOpts ¶ added in v1.0.0
GetScenarioOpts returns the browser options and environment variables associated with the given context.
func GetVU ¶
GetVU returns the attached k6 VU instance from ctx, which can be used to retrieve the sobek runtime and other k6 objects relevant to the currently executing VU. See https://github.com/grafana/k6/blob/v0.37.0/js/initcontext.go#L168-L186
func Panic ¶
Panic will cause a panic with the given error which will stop the current iteration. Before panicking, it will find the browser process from the context and kill it if it still exists. TODO: test.
func Promise ¶ added in v0.5.0
func Promise(ctx context.Context, fn PromisifiedFunc) *sobek.Promise
Promise runs fn in a goroutine and returns a new sobek.Promise.
- If fn returns a nil error, resolves the promise with the first result value fn returns.
- Otherwise, rejects the promise with the error fn returns.
func WithCustomMetrics ¶
func WithCustomMetrics(ctx context.Context, k6m *CustomMetrics) context.Context
WithCustomMetrics attaches the CustomK6Metrics object to the context.
Types ¶
type CustomMetrics ¶
type CustomMetrics struct { WebVitals map[string]*k6metrics.Metric BrowserDataSent *k6metrics.Metric BrowserDataReceived *k6metrics.Metric BrowserHTTPReqDuration *k6metrics.Metric BrowserHTTPReqFailed *k6metrics.Metric }
CustomMetrics are the custom k6 metrics used by xk6-browser.
func GetCustomMetrics ¶
func GetCustomMetrics(ctx context.Context) *CustomMetrics
GetCustomMetrics returns the CustomK6Metrics object attached to the context.
func RegisterCustomMetrics ¶
func RegisterCustomMetrics(registry *k6metrics.Registry) *CustomMetrics
RegisterCustomMetrics creates and registers our custom metrics with the k6 VU Registry and returns our internal struct pointer.
type PromisifiedFunc ¶ added in v0.5.0
PromisifiedFunc is a type of the function to run as a promise.
type UserFriendlyError ¶ added in v0.5.0
type UserFriendlyError struct { Err error Timeout time.Duration // prints "timed out after Ns" error }
UserFriendlyError maps an internal error to an error that users can easily understand.
func (*UserFriendlyError) Error ¶ added in v0.5.0
func (e *UserFriendlyError) Error() string
func (*UserFriendlyError) Unwrap ¶ added in v0.5.0
func (e *UserFriendlyError) Unwrap() error