modules

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: AGPL-3.0 Imports: 9 Imported by: 493

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

func GenerateExports added in v0.34.0

func GenerateExports(v interface{}) Exports

GenerateExports generates an Exports from a module akin to how common.Bind does now. it also skips anything that is expected will not want to be exported such as methods and fields coming from interfaces defined in this package.

type HasModuleInstancePerVU added in v0.32.0

type HasModuleInstancePerVU interface {
	NewModuleInstancePerVU() interface{}
}

HasModuleInstancePerVU should be implemented by all native Golang modules that would require per-VU state. k6 will call their NewModuleInstancePerVU() methods every time a VU imports the module and use its result as the returned object.

type Instance added in v0.34.0

type Instance interface {
	InstanceCore
	GetExports() Exports
}

Instance is what a module needs to return

type InstanceCore added in v0.34.0

type InstanceCore interface {
	GetContext() context.Context

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

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

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

InstanceCore is something that will be provided to modules and they need to embed it in ModuleInstance

type IsModuleV2 added in v0.34.0

type IsModuleV2 interface {
	// NewModuleInstance will get InstanceCore that should provide the module with *everything* it needs and return an
	// Instance implementation (embedding the InstanceCore).
	// This method will be called for *each* require/import and return an object for VUs.
	NewModuleInstance(InstanceCore) Instance
}

IsModuleV2 is the interface js modules should implement to get the version 2 of the system

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.
html
generated by js/modules/k6/html/gen/gen_elements.go directed by js/modules/k6/html/elements.go; DO NOT EDIT nolint: goconst
generated by js/modules/k6/html/gen/gen_elements.go directed by js/modules/k6/html/elements.go; DO NOT EDIT nolint: goconst
ws

Jump to

Keyboard shortcuts

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