Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Documentationbreadcrumb arrow Grafana k6breadcrumb arrow Extensionsbreadcrumb arrow Run a test with extensions
Open source RSS

Run a test with extensions

There are two different ways to run your k6 test script depending on the k6 extension you want to use: using the automatic extension resolution, or building a custom k6 binary.

Before you begin

Use automatic extension resolution

It’s as easy as importing them. Example with xk6-faker:

JavaScript
import faker from 'k6/x/faker';

export default function () {
  console.log(faker.person.firstName());
}

Then, you can run your script as usual, and k6 automatically detects the extension and loads it:

sh
k6 run script.js

Shell tab-completion also triggers automatic extension resolution. When you press Tab after typing an extension import path, k6 provisions the extension if it isn’t already available.

Limitations

  • Only works with Official and Community extensions.
  • Output extensions aren’t supported.
  • Running scripts from stdin isn’t supported.
  • Only files with extensions .js, .ts or .tar can be used.

Disable automatic extension resolution

You can disable this feature by setting the environment variable K6_AUTO_EXTENSION_RESOLUTION to false. If provided, the previous example fails because k6 can’t load the extension dynamically.

Bash
K6_AUTO_EXTENSION_RESOLUTION=false k6 run test.js

Use extensions with a custom k6 binary

To run other extensions (including ones you create), you need to build a custom k6 binary with xk6.

You can do this locally with Go or use the xk6 Docker image.

go-and-xk6
xk6 build \
  --with github.com/grafana/xk6-sql@v0.0.1 \
  --with github.com/grafana/xk6-output-influxdb
docker-in-linux
docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" grafana/xk6 build \
  --with github.com/grafana/xk6-sql@v0.0.1 \

For more details, refer to: