k6ext

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package k6ext acts as an encapsulation layer between the k6 core and xk6-browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort added in v0.9.0

func Abort(ctx context.Context, format string, a ...any)

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

func GetScenarioName(ctx context.Context) string

GetScenarioName returns the scenario name associated with the given context.

func GetScenarioOpts added in v1.0.0

func GetScenarioOpts(ctx context.Context, vu k6modules.VU) map[string]any

GetScenarioOpts returns the browser options and environment variables associated with the given context.

func GetVU

func GetVU(ctx context.Context) k6modules.VU

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

func Panic(ctx context.Context, format string, a ...any)

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 Runtime

func Runtime(ctx context.Context) *sobek.Runtime

Runtime is a convenience function for getting a k6 VU runtime.

func WithCustomMetrics

func WithCustomMetrics(ctx context.Context, k6m *CustomMetrics) context.Context

WithCustomMetrics attaches the CustomK6Metrics object to the context.

func WithVU

func WithVU(ctx context.Context, vu k6modules.VU) context.Context

WithVU returns a new context based on ctx with the k6 VU instance attached.

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

type PromisifiedFunc func() (result any, reason error)

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

Directories

Path Synopsis
Package k6test provides mock implementations of k6 elements for testing purposes.
Package k6test provides mock implementations of k6 elements for testing purposes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL