You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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]>
Copy file name to clipboardExpand all lines: docs/sources/next/get-started/resources.md
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,7 @@ These resources help you write and run k6 tests in a safe environment and explor
14
14
15
15
## Learning
16
16
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.
19
18
-[k6 Learn](https://github.com/grafana/k6-learn). A repository with a course and a ton of learning resources.
20
19
-[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.
21
20
-[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.
43
42
-[Kubernetes Operator](https://k6.io/blog/running-distributed-tests-on-k8s/). Distribute test execution across a Kubernetes cluster.
44
43
-[xk6 extensions](https://grafana.com/docs/k6/<K6_VERSION>/extensions). Custom k6 binaries to support the tool you need.
45
44
-[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.
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'
7
7
weight: 19
8
8
---
9
9
10
-
# JavaScript compatibility mode
10
+
# JavaScript and TypeScript compatibility mode
11
11
12
12
You can write k6 scripts in various ECMAScript versions:
13
13
@@ -20,9 +20,12 @@ To enable ES module support, k6 uses [Babel](https://babeljs.io/) internally to
20
20
21
21

22
22
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:
24
26
25
27
-[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.
26
29
-[Base mode](#base-mode): Limited to CommonJS, excluding the Babel step.
27
30
28
31
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
47
50
48
51
Currently, the k6 Babel transformation only adds ESM support and sets `global` (node's global variable) with the value of `globalThis`.
49
52
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.
Copy file name to clipboardExpand all lines: docs/sources/next/using-k6/modules.md
+1-4Lines changed: 1 addition & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -355,10 +355,7 @@ $ k6 run dist/signup.bundle.js \
355
355
356
356
## Use TypeScript
357
357
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/).
0 commit comments