Make the Node.js ecosystem available for k6 tests

xk6-plugin v0.1.0 is here :tada:!

Create k6 plugins using JavaScript and Node.js

The xk6-plugin k6 extension makes the Node.js runtime available to k6 tests using k6 plugins. Plugins are executed by a modern Node.js compatible runtime (Deno or Bun), so they can use the entire Node.js ecosystem.

In simple terms, a plugin is nothing more than a JavaScript (or TypeScript) module executed on the Node.js runtime, whose exported functions are available from k6 tests. Both Deno and Bun runtimes are supported.

Features

  • the entire Node.js ecosystem is available, millions of packages
  • plugins can be written in TypeScript/JavaScript
  • modern Node.js compatible JavaScript runtime (Deno or Bun)
  • no go language skills required
  • plugin development does not require a custom k6 build
  • plugins are ESM modules, no need to learn a new API
  • plugins can be tested without k6
  • k6 tests and plugins can be written in the same language

Quick start

  1. Download the archive from the Releases page for your operating system and extract the k6 executable from it.

  2. Download and install Deno and/or Bun.

  3. Create a plugin, let’s say hello.plugin.js:

    export function hello() {
      return "Hello, World!"
    }
    
  4. Create a k6 test script that uses this plugin, let’s say script.js:

    import { hello } from "k6/x/plugin/./hello.plugin.js"
    
    export default async function() {
      console.log(await hello())
    }
    
  5. Run the k6 test script:

    k6 run -q --no-summary script.js
    

    You will get something like this output:

    INFO[0000] deno 2.2.2 started with ./hello.plugin.js    
    INFO[0000] Hello, World!                                 source=console
    

:tada: Congratulations, you have created and used your first k6 plugin!