modules

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: AGPL-3.0 Imports: 7 Imported by: 495

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJSModules added in v0.32.0

func GetJSModules() map[string]interface{}

GetJSModules returns a map of all registered js modules

func Register added in v0.32.0

func Register(name string, mod interface{})

Register the given mod as an external JavaScript module that can be imported by name. The name must be unique across all registered modules and must be prefixed with "k6/x/", otherwise this function will panic.

Types

type Exports added in v0.34.0

type Exports struct {
	// Default is what will be the `default` export of a module
	Default interface{}
	// Named is the named exports of a module
	Named map[string]interface{}
}

Exports is representation of ESM exports of a module

type Instance added in v0.34.0

type Instance interface {
	Exports() Exports
}

Instance is what a module needs to return

type Module added in v0.35.0

type Module interface {
	// NewModuleInstance will get modules.VU that should provide the module with a way to interact with the VU
	// This method will be called for *each* require/import and should return an unique instance for each call
	NewModuleInstance(VU) Instance
}

Module is the interface js modules should implement in order to get access to the VU

type VU added in v0.35.0

type VU interface {
	// Context return the context.Context about the current VU
	Context() context.Context

	// InitEnv returns common.InitEnvironment instance if present
	InitEnv() *common.InitEnvironment

	// State returns lib.State if any is present
	State() *lib.State

	// Runtime returns the goja.Runtime for the current VU
	Runtime() *goja.Runtime

	// RegisterCallback lets a module declare that it wants to run a function on the event loop *at a later point in time*.
	// It needs to be called from within the event loop, so not in a goroutine spawned by a module.
	// Its result can be called with a function that will be executed *on the event loop* -
	// possibly letting you call RegisterCallback again.
	// Calling the result can be done at any time. The event loop will block until that happens, (if it doesn't
	// have something else to run) so in the event of an iteration end or abort (for example due to an exception),
	// It is the module responsibility to monitor the context and abort on it being done.
	// This still means that the returned function here *needs* to be called to signal that the module
	// has aborted the operation and will not do anything more, not doing so will block k6.
	//
	// Experimental
	//
	// Notice: This API is EXPERIMENTAL and may be changed or removed in a later release.
	RegisterCallback() func(func() error)
}

VU gives access to the currently executing VU to a module Instance

Directories

Path Synopsis
k6
Package k6 implements the module imported as 'k6' from inside k6.
Package k6 implements the module imported as 'k6' from inside k6.
experimental
Package experimental includes experimental module features
Package experimental includes experimental module features
html
generated by js/modules/k6/html/gen/gen_elements.go; DO NOT EDIT
generated by js/modules/k6/html/gen/gen_elements.go; DO NOT EDIT
ws

Jump to

Keyboard shortcuts

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