Skip to content

Commit fc7272f

Browse files
committed
Backport JS extension changes to v1.0.x and v1.1.x
1 parent ea25867 commit fc7272f

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

docs/sources/k6/v1.0.x/extensions/create/javascript-extensions.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ INFO[0000] false, 1 is NOT greater than 3 source=console
161161

162162
## Use the advanced module API
163163

164+
{{< admonition type="caution" >}}
165+
166+
The advanced module API adds significant complexity to your extension. Consider whether you actually need access to internal
167+
k6 objects before implementing this pattern. For simple modules that don't need VU state or runtime access, the basic approach
168+
shown above is sufficient.
169+
170+
{{< /admonition >}}
171+
164172
Suppose your extension needs access to internal k6 objects to, for example, inspect the state of the test during execution.
165173
We will need to make slightly more complicated changes to the above example.
166174

@@ -174,12 +182,6 @@ to access the [`modules.VU`](https://pkg.go.dev/go.k6.io/k6/js/modules#VU) to in
174182
Additionally, there should be a root module implementation of the [`modules.Module`](https://pkg.go.dev/go.k6.io/k6/js/modules#Module)
175183
interface to serve as a factory of `Compare` instances for each VU.
176184

177-
{{< admonition type="caution" >}}
178-
179-
The significance depends on the size of your module.
180-
181-
{{< /admonition >}}
182-
183185
Here's what that would look like:
184186

185187
{{< code >}}
@@ -323,9 +325,6 @@ INFO[0000] Active VUs: 2, Iteration: 1, VU ID: 1, VU ID from runtime: 1 source=
323325
INFO[0000] Active VUs: 2, Iteration: 2, VU ID: 2, VU ID from runtime: 2 source=console
324326
```
325327

326-
> For a more extensive usage example of this API, look at the
327-
> [`k6/execution`](https://github.com/grafana/k6/blob/master/js/modules/k6/execution/execution.go) module.
328-
329328
## Things to keep in mind
330329

331330
- The code in the `default` function (or another function specified by

docs/sources/k6/v1.1.x/extensions/create/javascript-extensions.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ INFO[0000] false, 1 is NOT greater than 3 source=console
161161

162162
## Use the advanced module API
163163

164+
{{< admonition type="caution" >}}
165+
166+
The advanced module API adds significant complexity to your extension. Consider whether you actually need access to internal
167+
k6 objects before implementing this pattern. For simple modules that don't need VU state or runtime access, the basic approach
168+
shown above is sufficient.
169+
170+
{{< /admonition >}}
171+
164172
Suppose your extension needs access to internal k6 objects to, for example, inspect the state of the test during execution.
165173
We will need to make slightly more complicated changes to the above example.
166174

@@ -174,12 +182,6 @@ to access the [`modules.VU`](https://pkg.go.dev/go.k6.io/k6/js/modules#VU) to in
174182
Additionally, there should be a root module implementation of the [`modules.Module`](https://pkg.go.dev/go.k6.io/k6/js/modules#Module)
175183
interface to serve as a factory of `Compare` instances for each VU.
176184

177-
{{< admonition type="caution" >}}
178-
179-
The significance depends on the size of your module.
180-
181-
{{< /admonition >}}
182-
183185
Here's what that would look like:
184186

185187
{{< code >}}
@@ -323,9 +325,6 @@ INFO[0000] Active VUs: 2, Iteration: 1, VU ID: 1, VU ID from runtime: 1 source=
323325
INFO[0000] Active VUs: 2, Iteration: 2, VU ID: 2, VU ID from runtime: 2 source=console
324326
```
325327

326-
> For a more extensive usage example of this API, look at the
327-
> [`k6/execution`](https://github.com/grafana/k6/blob/master/js/modules/k6/execution/execution.go) module.
328-
329328
## Things to keep in mind
330329

331330
- The code in the `default` function (or another function specified by

0 commit comments

Comments
 (0)