k6ext

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: AGPL-3.0 Imports: 10 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 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

func GetProcessID(ctx context.Context) int

GetProcessID returns the browser process ID from the 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 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

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

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 Runtime

func Runtime(ctx context.Context) *goja.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 WithProcessID

func WithProcessID(ctx context.Context, pid int) context.Context

WithProcessID saves the browser process ID 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 {
	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

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

Jump to

Keyboard shortcuts

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