Skip to content

Commit f8481ea

Browse files
joanlopezheitortsergent
authored andcommitted
Document 'experimental_enhanced' compatibility mode (grafana#1630)
* Document 'experimental_enhanced' compatibility mode * Replace script.js with script.ts * Add alias * Remove property to hide page from menu * Rename page and update page title * Add links to esbuild * Update mentions of TypeScript to link to compatibility mode --------- Co-authored-by: Heitor Tashiro Sergent <[email protected]>
1 parent 911717d commit f8481ea

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

docs/sources/next/examples/tutorials/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ weight: 26
1212
- [Swagger/OpenAPI integration](https://k6.io/blog/load-testing-your-api-with-swagger-openapi-and-k6)
1313
- [Schedule k6 tests with cron](https://k6.io/blog/performance-monitoring-with-cron-and-k6)
1414
- [Load test a GraphQL service](https://k6.io/blog/load-testing-graphql-with-k6)
15-
- [Use TypeScript in k6 scripts](https://github.com/k6io/template-typescript)
15+
- [Use TypeScript in k6 scripts](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/javascript-typescript-compatibility-mode/)
1616
- [Debug using a Web Proxy](https://k6.io/blog/k6-load-testing-debugging-using-a-web-proxy/)
1717
- [Distributed k6 tests on K8s](https://k6.io/blog/running-distributed-tests-on-k8s/)
1818
- [Create a k6 extension](https://k6.io/blog/extending-k6-with-xk6)

docs/sources/next/get-started/resources.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ These resources help you write and run k6 tests in a safe environment and explor
1414

1515
## Learning
1616

17-
- [Get started with k6 tutorial](https://grafana.com/docs/k6/<K6_VERSION>/examples/get-started-with-k6). The getting started tutorial provides some procedures for common real-life uses of k6 and does not require prior knowledge of k6 or JavaScript
18-
17+
- [Get started with k6 tutorial](https://grafana.com/docs/k6/<K6_VERSION>/examples/get-started-with-k6). The getting started tutorial provides some procedures for common real-life uses of k6 and does not require prior knowledge of k6 or JavaScript.
1918
- [k6 Learn](https://github.com/grafana/k6-learn). A repository with a course and a ton of learning resources.
2019
- [k6 OSS workshop](https://github.com/grafana/k6-oss-workshop). A 2-3 hour k6 workshop with practical k6 examples using the QuickPizza demo app.
2120
- [k6 YouTube channel](https://www.youtube.com/playlist?list=PLDGkOdUX1UjrZM3lIHvFcKJxVgl2n4J65). Office hours, specific playlists, and other interesting videos from the community.
@@ -43,5 +42,5 @@ Note that these are shared testing environments - please avoid high-load tests.
4342
- [Kubernetes Operator](https://k6.io/blog/running-distributed-tests-on-k8s/). Distribute test execution across a Kubernetes cluster.
4443
- [xk6 extensions](https://grafana.com/docs/k6/<K6_VERSION>/extensions). Custom k6 binaries to support the tool you need.
4544
- [The browser recorder](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/test-authoring/create-tests-from-recordings/using-the-browser-recorder). Make test scripts from browser sessions.
46-
- [k6 TypeScript template](https://github.com/grafana/k6-template-typescript)
45+
- [Use TypeScript in k6 scripts](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/javascript-typescript-compatibility-mode/)
4746
- [Integrations](https://grafana.com/docs/k6/<K6_VERSION>/misc/integrations)

docs/sources/next/set-up/configure-k6-intellisense.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ $ npm install --save-dev @types/k6
3636
- [Visual Studio Code - k6 Extension](https://marketplace.visualstudio.com/items?itemName=k6.k6)
3737
- [IntelliJ IDEA - k6 Plugin](https://plugins.jetbrains.com/plugin/16141-k6)
3838
- [TypeScript Editor Support](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support)
39+
- [Use TypeScript in k6 scripts](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/javascript-typescript-compatibility-mode/)

docs/sources/next/using-k6/javascript-compatibility-mode.md renamed to docs/sources/next/using-k6/javascript-typescript-compatibility-mode.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: JavaScript compatibility mode
3-
menuTitle: JavaScript mode
4-
excerpt: 'k6 supports running test scripts with different ECMAScript compatibility modes using --compatibility-mode'
5-
_build:
6-
list: false
2+
aliases:
3+
- ./javascript-compatibility-mode/ # /docs/k6/<K6_VERSION>/using-k6/javascript-compatibility-mode/
4+
title: JavaScript and TypeScript compatibility mode
5+
menuTitle: JavaScript and TypeScript mode
6+
excerpt: 'k6 supports running test scripts with different ECMAScript and TypeScript compatibility modes using --compatibility-mode'
77
weight: 19
88
---
99

10-
# JavaScript compatibility mode
10+
# JavaScript and TypeScript compatibility mode
1111

1212
You can write k6 scripts in various ECMAScript versions:
1313

@@ -20,9 +20,12 @@ To enable ES module support, k6 uses [Babel](https://babeljs.io/) internally to
2020

2121
![Babel transformation in k6](/media/docs/k6-oss/diagram-grafana-k6-babel-pipeline.png)
2222

23-
Some users prefer to bundle their test code outside k6. For this reason, k6 offers two JavaScript compatibility modes:
23+
Additionally, k6 also has experimental support for [esbuild](https://esbuild.github.io/), to transpile TypeScript (TS) code and to support most ES6+ features.
24+
25+
Some users prefer to bundle their test code outside k6. For this reason, k6 offers three JavaScript compatibility modes:
2426

2527
- [Extended mode](#extended-mode): The default option, supporting ESM and most ES6+ features.
28+
- [Experimental enhanced mode](#experimental-enhanced-mode): The experimental option, supporting TS and most ES6+ features.
2629
- [Base mode](#base-mode): Limited to CommonJS, excluding the Babel step.
2730

2831
When running tests, you can change the mode by using the `--compatibility-mode` option:
@@ -47,6 +50,24 @@ As illustrated in the previous diagram, if k6 detects unsupported ES+ features w
4750

4851
Currently, the k6 Babel transformation only adds ESM support and sets `global` (node's global variable) with the value of `globalThis`.
4952

53+
## Experimental enhanced mode
54+
55+
{{< code >}}
56+
57+
```cli
58+
$ k6 run --compatibility-mode=experimental_enhanced script.ts
59+
```
60+
61+
```env
62+
$ K6_COMPATIBILITY_MODE=experimental_enhanced k6 run script.ts
63+
```
64+
65+
{{< /code >}}
66+
67+
The experimental enhanced mode is similar to the extended mode, but it uses [esbuild](https://esbuild.github.io/) instead of Babel to transpile TypeScript (TS) code and to support most ES6+ features.
68+
69+
TypeScript support is partial as it removes the type information but doesn't provide type safety.
70+
5071
## Base mode
5172

5273
{{< code >}}

docs/sources/next/using-k6/modules.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,7 @@ $ k6 run dist/signup.bundle.js \
355355

356356
## Use TypeScript
357357

358-
k6 does not natively support TypeScript. If you wish to write k6 tests in Typescript, you will need a bundler, as demonstrated in the previous examples:
359-
360-
- Using Webpack: Refer to [k6-template-typescript](https://github.com/grafana/k6-template-typescript) and [k6-jslib-aws](https://github.com/grafana/k6-jslib-aws).
361-
- Using Rollup: Apply the [@rollup/plugin-typescript](https://github.com/rollup/plugins/tree/master/packages/typescript) to the [k6-rollup-example](https://github.com/grafana/k6-rollup-example).
358+
k6 supports partial TypeScript support with the `experimental_enhanced` compatibility mode. For more details, refer to [JavaScript and TypeScript compatibility mode](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/javascript-typescript-compatibility-mode/).
362359

363360
## Use modules with Docker
364361

0 commit comments

Comments
 (0)