A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://grafana.com/docs/k6/latest/using-k6/javascript-typescript-compatibility-mode/ below:

JavaScript and TypeScript compatibility mode

Open source

JavaScript compatibility mode

Note

If you’re using k6 v0.53 or higher, the compatibility mode feature doesn’t have much impact on the k6 default behavior. Refer to this GitHub issue for more details.

Starting on k6 v0.57, TypeScript support is enabled by default, and the experimental-enhanced-mode option has been removed.

k6 offers two JavaScript compatibility modes:

After k6 v0.53.0, the only difference between the base and extended modes is that global, the Node.js global variable, is aliased to the value of globalThis.

When running tests, you can change the mode by using the --compatibility-mode option:

Env CLI Code / Config file Default K6_COMPATIBILITY_MODE --compatibility-mode N/A "extended" Extended mode

By default, k6 uses the --compatibility-mode=extended mode:

Base mode
k6 run --compatibility-mode=base script.js
K6_COMPATIBILITY_MODE=base k6 run script.js
Typescript support

k6 uses esbuild to transpile TypeScript (TS) code for all files that have the .ts extension.

TypeScript support is partial as it strips the type information but doesn’t provide type safety.

CommonJS Example
const http = require('k6/http');
const k6 = require('k6');

module.exports.options = {
  vus: 10,
  duration: '30s',
};

module.exports.default = function () {
  http.get('http://test.k6.io');
  k6.sleep(1);
};
⚠️ About require()

Note that require() is a custom k6 implementation of module loading, which doesn’t behave in the same way as the require() call in Node.js. Specifically, it only handles loading of built-in k6 modules, scripts on the local filesystem, and remote scripts over HTTP(S), but it does not support the Node.js module resolution algorithm.

Bundling with Babel outside of k6

The examples below demonstrate the use of Babel with bundlers like Webpack and Rollup:

Read more

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4