Documentation ¶
Overview ¶
Package k6ext acts as an encapsulation layer between the k6 core and xk6-browser.
Index ¶
- func AbortingPromise(ctx context.Context, fn PromisifiedFunc) *goja.Promise
- func GetProcessID(ctx context.Context) int
- func GetVU(ctx context.Context) k6modules.VU
- func OnCloud() bool
- func Panic(ctx context.Context, format string, a ...any)
- func Promise(ctx context.Context, fn PromisifiedFunc) *goja.Promise
- func Runtime(ctx context.Context) *goja.Runtime
- func WithCustomMetrics(ctx context.Context, k6m *CustomMetrics) context.Context
- func WithProcessID(ctx context.Context, pid int) 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 AbortingPromise ¶ added in v0.5.0
func AbortingPromise(ctx context.Context, fn PromisifiedFunc) *goja.Promise
AbortingPromise is like Promise, but it aborts the event loop if an error occurs.
func GetProcessID ¶
GetProcessID returns the browser process ID from the context.
func GetVU ¶
GetVU returns the attached k6 VU instance from ctx, which can be used to retrieve the goja 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 OnCloud ¶ added in v0.6.0
func OnCloud() bool
OnCloud returns true if xk6-browser runs in the cloud.
func Panic ¶
Panic will cause a panic with the given error which will shut the application down. 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) *goja.Promise
Promise runs fn in a goroutine and returns a new goja.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.
func WithProcessID ¶
WithProcessID saves the browser process ID to the context.
Types ¶
type CustomMetrics ¶
type CustomMetrics struct { BrowserDOMContentLoaded *k6metrics.Metric BrowserFirstPaint *k6metrics.Metric BrowserFirstContentfulPaint *k6metrics.Metric BrowserFirstMeaningfulPaint *k6metrics.Metric BrowserLoaded *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