Documentation ¶
Overview ¶
Package modules defines interfaces used for developing k6's JavaScript modules.
Index ¶
- func ExportGloballyModule(rt *sobek.Runtime, modSys *ModuleSystem, moduleName string)
- func Register(name string, mod interface{})
- type Exports
- type FileLoader
- type Instance
- type Module
- type ModuleResolver
- type ModuleSystem
- func (ms *ModuleSystem) CurrentlyRequiredModule() (*url.URL, error)
- func (ms *ModuleSystem) Require(specifier string) (*sobek.Object, error)
- func (ms *ModuleSystem) Resolve(mr sobek.ModuleRecord, specifier string) (*url.URL, error)
- func (ms *ModuleSystem) RunSourceData(source *loader.SourceData) (*RunSourceDataResult, error)
- func (ms *ModuleSystem) ShouldWarnOnParentDirNotMatchingCurrentModuleParentDir(vu VU, parentModulePwd *url.URL) (string, bool)
- type RunSourceDataResult
- type VU
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExportGloballyModule ¶ added in v0.51.0
func ExportGloballyModule(rt *sobek.Runtime, modSys *ModuleSystem, moduleName string)
ExportGloballyModule sets all exports of the provided module name on the globalThis. effectively making them globally available
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 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]any, loadCJS FileLoader, c *compiler.Compiler, base *url.URL, u *usage.Usage, logger logrus.FieldLogger, ) *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
func (*ModuleResolver) Imported ¶ added in v0.49.0
func (mr *ModuleResolver) Imported() []string
Imported returns the list of imported and resolved modules. Each string represents the path as used for importing.
func (*ModuleResolver) Lock ¶ added in v0.51.0
func (mr *ModuleResolver) Lock()
Lock locks the module's resolution from any further new resolving operation. It means that it relays only its internal cache and on the fact that it has already seen previously the module during the initialization. It is the same approach used for opening file operations.
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) CurrentlyRequiredModule ¶ added in v0.53.0
func (ms *ModuleSystem) CurrentlyRequiredModule() (*url.URL, error)
CurrentlyRequiredModule returns the module that is currently being required. It is mostly used for old and somewhat buggy behaviour of the `open` call
func (*ModuleSystem) Require ¶ added in v0.45.0
func (ms *ModuleSystem) Require(specifier string) (*sobek.Object, error)
Require is the actual call that implements require
func (*ModuleSystem) Resolve ¶ added in v0.53.0
func (ms *ModuleSystem) Resolve(mr sobek.ModuleRecord, specifier string) (*url.URL, error)
Resolve returns what the provided specifier will get resolved to if it was to be imported To be used by other parts to get the path
func (*ModuleSystem) RunSourceData ¶ added in v0.45.0
func (ms *ModuleSystem) RunSourceData(source *loader.SourceData) (*RunSourceDataResult, 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.
func (*ModuleSystem) ShouldWarnOnParentDirNotMatchingCurrentModuleParentDir ¶ added in v0.55.0
func (ms *ModuleSystem) ShouldWarnOnParentDirNotMatchingCurrentModuleParentDir(vu VU, parentModulePwd *url.URL, ) (string, bool)
ShouldWarnOnParentDirNotMatchingCurrentModuleParentDir is a helper function to figure out if the provided url is the same folder that an import will be to. It also checks if the modulesystem is locked which means we are past the first init context. If false is returned means that we are not in the init context or the path is matching - so no warning should be done If true, the returned path is the module path that it should be relative to - the one that is checked against.
type RunSourceDataResult ¶ added in v0.55.0
type RunSourceDataResult struct {
// contains filtered or unexported fields
}
RunSourceDataResult helps with the asynchronous nature of ESM it wraps the promise that is returned from Sobek while at the same time allowing access to the module record
func (*RunSourceDataResult) Result ¶ added in v0.55.0
func (r *RunSourceDataResult) Result() (sobek.ModuleRecord, bool, error)
Result returns either the underlying module or error if the promise has been completed and true, or false if the promise still hasn't been completed
type VU ¶ added in v0.35.0
type VU interface { // Context return the context.Context about the current VU Context() context.Context // Events allows subscribing to global k6 execution events, such as Init and // Exit, and to local (per-VU) events, such as IterStart and IterEnd. // NOTE: This API is EXPERIMENTAL and may be changed, renamed or // completely removed in a later k6 release. // FIXME: Subscribing to global events shouldn't be part of this VU (local) // interface. Events() common.Events // InitEnv returns common.InitEnvironment instance if present InitEnv() *common.InitEnvironment // State returns lib.State if any is present State() *lib.State // Runtime returns the sobek.Runtime for the current VU Runtime() *sobek.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. 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. |
crypto
Package crypto provides common hashing function for the k6
|
Package crypto provides common hashing function for the k6 |
crypto/x509
Package x509 provides X.509 certificate parsing for the k6
|
Package x509 provides X.509 certificate parsing for the k6 |
data
Package data implements `k6/data` js module for k6.
|
Package data implements `k6/data` js module for k6. |
encoding
Package encoding provides encoding/decoding functionality for the k6
|
Package encoding provides encoding/decoding functionality for the k6 |
execution
Package execution implements k6/execution which lets script find out more about it is execution.
|
Package execution implements k6/execution which lets script find out more about it is execution. |
experimental
Package experimental includes experimental module features
|
Package experimental includes experimental module features |
experimental/csv
Package csv provides a CSV parser for k6.
|
Package csv provides a CSV parser for k6. |
experimental/fs
Package fs provides a k6 module that allows users to interact with files from the local filesystem as per the [File API design document].
|
Package fs provides a k6 module that allows users to interact with files from the local filesystem as per the [File API design document]. |
experimental/streams
Package streams provides support for the Web Streams API.
|
Package streams provides support for the Web Streams API. |
grpc
Package grpc is the root module of the k6-grpc extension.
|
Package grpc is the root module of the k6-grpc extension. |
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 |
html/gen
Package main - this package generates some of the code for k6/html
|
Package main - this package generates some of the code for k6/html |
http
Package http implements the k6/http js module for k6.
|
Package http implements the k6/http js module for k6. |
metrics
Package metrics implements k6/metrics and let script work with custom metrics.
|
Package metrics implements k6/metrics and let script work with custom metrics. |
timers
Package timers is implementing setInterval setTimeout and co.
|
Package timers is implementing setInterval setTimeout and co. |
ws
Package ws implements a k6/ws for k6.
|
Package ws implements a k6/ws for k6. |