Profile
Back to NewsBack
GitHub Trending 3 min
Reader Mode
grafana/har-to-k6: JSON config representation of k6 script

grafana/har-to-k6: JSON config representation of k6 script

20 hours ago



Content

- Local Installation (recommended) - Global Installation - Docker - CLI Usage - Programmatic Usage - Browser Usage

Installation

Local Installation (recommended)

While possible to install globally, we recommend that you, if possible, add the converter to the node_modules of your test project using:

$ npm install --save har-to-k6

Note that this will require you to run the converter with npx har-to-k6 your-har-file or, if you are using an older version of npm, ./node_modules/.bin/har-to-k6 your-har-file.

Global Installation

$ npm install --global har-to-k6

Docker

$ docker pull grafana/har-to-k6:latest

Usage

CLI Usage

Npx

$ npx har-to-k6 archive.har -o my-k6-script.js

From node_modules

$ ./node_modules/.bin/har-to-k6 archive.har -o my-k6-script.js

Global

$ har-to-k6 archive.har -o my-k6-script.js

Docker

$ docker run grafana/har-to-k6:latest archive.har > my-k6-script.js

Programmatic Usage

Converting

const fs = require("fs");
const { liHARToK6Script } = require("har-to-k6");

async function run () { const archive = readArchive(); const { main } = await liHARToK6Script(archive); fs.writeFileSync("./load-test.js", main); }

Validating

Use validate() to run validation alone. Returns without error for a valid archive. Throws InvalidArchiveError for validation failure.

const { InvalidArchiveError, validate } = require("har-to-k6");

const archive = readArchive(); try { validate(archive); } catch (error) { if (error instanceof InvalidArchiveError) { // Handle invalid archive } else { throw error; } }

Browser Usage

har-to-k6 can be ran in the browser. This exposes the standard API under harToK6.

Importing as ES module

import { liHARToK6Script } from "har-to-k6";

CommonJS style

const { liHARToK6Script } = require("har-to-k6");

Using a Chat with me