Make the Node.js ecosystem available for k6 tests (original) (raw)

xk6-plugin v0.1.0 is here ๐ŸŽ‰!

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

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!"  
}  
  1. 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())  
}  
  1. 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  

๐ŸŽ‰ Congratulations, you have created and used your first k6 plugin!