From 6ffcc1f363a892ed0b6e46c3d5b9bf6abc4336dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Miri=C4=87?= Date: Thu, 7 Oct 2021 12:28:12 +0200 Subject: [PATCH] Fix exports in advanced JS module example Resolves https://github.com/grafana/k6-docs/pull/346#discussion_r723933014 --- .../en/07 Misc/05 k6 Extensions.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/data/markdown/translated-guides/en/07 Misc/05 k6 Extensions.md b/src/data/markdown/translated-guides/en/07 Misc/05 k6 Extensions.md index 6c9fd08b49..b64ddd2ad7 100644 --- a/src/data/markdown/translated-guides/en/07 Misc/05 k6 Extensions.md +++ b/src/data/markdown/translated-guides/en/07 Misc/05 k6 Extensions.md @@ -348,6 +348,8 @@ type ( // InstanceCore provides some useful methods for accessing internal k6 // objects like the global context, VU state and goja runtime. modules.InstanceCore + // Comparator is the exported module instance. + *Comparator } ) @@ -365,18 +367,21 @@ func New() *RootModule { // NewModuleInstance implements the modules.IsModuleV2 interface and returns // a new instance for each VU. func (*RootModule) NewModuleInstance(m modules.InstanceCore) modules.Instance { - return &Compare{InstanceCore: m} + return &Compare{InstanceCore: m, Comparator: &Comparator{}} +} + +// Comparator is the exported module instance. +type Comparator struct{} + +// IsGreater returns true if a is greater than b, or false otherwise. +func (*Comparator) IsGreater(a, b int) bool { + return a > b } // GetExports implements the modules.Instance interface and returns the exports // of the JS module. func (c *Compare) GetExports() modules.Exports { - return modules.Exports{Default: c} -} - -// IsGreater returns true if a is greater than b, false otherwise. -func (*Compare) IsGreater(a, b int) bool { - return a > b + return modules.Exports{Default: c.Comparator} } ```