Documentation ¶
Overview ¶
Package modules defines interfaces used for developing k6's JavaScript modules.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 FileLoader ¶ added in v0.45.0
FileLoader is a type alias for a function that returns the contents of the referenced file.
type Instance ¶ added in v0.34.0
type Instance interface {
Exports() Exports
}
Instance is what a module needs to return
type LegacyRequireImpl ¶ added in v0.45.0
type LegacyRequireImpl struct {
// contains filtered or unexported fields
}
LegacyRequireImpl is a legacy implementation of `require()` that is not compatible with CommonJS as it loads modules relative to the currently required file, instead of relative to the file the `require()` is written in. See https://github.com/grafana/k6/issues/2674
func NewLegacyRequireImpl ¶ added in v0.45.0
func NewLegacyRequireImpl(vu VU, ms *ModuleSystem, pwd url.URL) *LegacyRequireImpl
NewLegacyRequireImpl creates a new LegacyRequireImpl
func (*LegacyRequireImpl) CurrentlyRequiredModule ¶ added in v0.45.0
func (r *LegacyRequireImpl) CurrentlyRequiredModule() url.URL
CurrentlyRequiredModule returns the module that is currently being required. It is mostly used for old and somewhat buggy behaviour of the `open` call
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 ModuleResolver ¶ added in v0.45.0
type ModuleResolver struct {
// contains filtered or unexported fields
}
ModuleResolver knows how to get base Module that can be initialized
func NewModuleResolver ¶ added in v0.45.0
func NewModuleResolver(goModules map[string]interface{}, loadCJS FileLoader, c *compiler.Compiler) *ModuleResolver
NewModuleResolver returns a new module resolution instance that will resolve. goModules is map of import file to a go module loadCJS is used to load commonjs files
type ModuleSystem ¶ added in v0.45.0
type ModuleSystem struct {
// contains filtered or unexported fields
}
ModuleSystem is implementing an ESM like module system to resolve js modules for k6 usage
func NewModuleSystem ¶ added in v0.45.0
func NewModuleSystem(resolver *ModuleResolver, vu VU) *ModuleSystem
NewModuleSystem returns a new ModuleSystem for the provide VU using the provided resoluter
func (*ModuleSystem) Require ¶ added in v0.45.0
Require is called when a module/file needs to be loaded by a script
func (*ModuleSystem) RunSourceData ¶ added in v0.45.0
func (ms *ModuleSystem) RunSourceData(source *loader.SourceData) (goja.Value, error)
RunSourceData runs the provided sourceData and adds it to the cache. If a module with the same specifier as the source is already cached it will be used instead of reevaluating the source from the provided SourceData.
TODO: this API will likely change as native ESM support will likely not let us have the exports as one big goja.Value that we can manipulate
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 JS module declare that it wants to run a function // on the event loop *at a later point in time*. See the documentation for // `EventLoop.RegisterCallback()` in the `k6/js/eventloop` Go module for // the very important details on its usage and restrictions. // // Notice: This API is EXPERIMENTAL and may be changed, renamed or // completely removed in a later k6 release. RegisterCallback() (enqueueCallback func(func() error)) }
VU gives access to the currently executing VU to a module Instance
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package k6 implements the module imported as 'k6' from inside k6.
|
Package k6 implements the module imported as 'k6' from inside k6. |
data
Package data implements `k6/data` js module for k6.
|
Package data implements `k6/data` js module for k6. |
experimental
Package experimental includes experimental module features
|
Package experimental includes experimental module features |
experimental/browser
Package browser contains a RootModule wrapper that wraps around the experimental browser RootModule.
|
Package browser contains a RootModule wrapper that wraps around the experimental browser RootModule. |
experimental/tracing
Package tracing implements a k6 JS module for instrumenting k6 scripts with tracing context information.
|
Package tracing implements a k6 JS module for instrumenting k6 scripts with tracing context information. |
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 |
http
Package http implements the k6/http js module for k6.
|
Package http implements the k6/http js module for k6. |
ws
Package ws implements a k6/ws for k6.
|
Package ws implements a k6/ws for k6. |